﻿#include "mainwindow_thread.h"
#include "camera_thread.h"

//=================================================================================================================================================
//Define 
//=================================================================================================================================================
int ae_exposure;
int ae_again;
int ae_dgain;
int ae_ispdgain;
int csc_brightness;
int csc_constrast;
int csc_hue;
int csc_saturation;
int awb_awbmode;
int awb_temperature;
int awb_rgain;
int awb_grgain;
int awb_gbgain;
int awb_bgain;
int sharp_mode;
int sharp_texturefreq;
int sharp_edgefreq;
int sharp_overshoot;
int sharp_undershoot;
int nr_enable;
int nr_mode;
int nr_chroma;
int nr_fine;
int nr_coring;
int nr_coar;
int ccm_mode;
int ccm_rr;
int ccm_rg;
int ccm_rb;
int ccm_gr;
int ccm_gg;
int ccm_gb;
int ccm_br;
int ccm_bg;
int ccm_bb;
int lookfiletype = 0;
int sample=0;

int DPC_BlendRatio;
int DPC_Strength;

int DE_enable;
int DE_model;
int DE_GlobaGain;
int DE_GainLF;
int DE_GainHF;
int LDCI_en;
int LDCI_mode;
int LDCI_LPFSigma;
int LDCI_Blc;
int LDCI_posmean;
int LDCI_possigma;
int LDCI_poswgt;
int LDCI_negmean;
int LDCI_negsigma;
int LDCI_negwgt;
int CAMERA_MODLE;
int HDMI_OUT;
int KEY_AL;
int KEY_AS;
int KEY_BL;
int KEY_BS;
int save_value;
int CAM_CHANGE_EN;      //是否允许摄像头的输入模式切换DVP&MIPI
int led_value;          //led 亮度等级
int led_status;         //led 开启关闭状态
int ae_mode;
int backlight_value;
int curtimeindex;
int cur_index =1000000;
int lightflag = 0;
int ficeflag = 0;

extern int startPlayAvi;
extern int pausePlayAvi;
extern char videoPath[50];
extern char h265Path[50];
extern int totalFrame;
extern int playFrame;
extern int decodeFrame;
extern int playFlag;
extern int decodeFlag;

int back_mode = 1;
int noFreeRoom_flag = 0;
int storage = 0;
int storage_sd = 0;
int storage_udisk = 0;
int camera_type = 0;
int rec_flag=0;

int KEY_A_SHORT=0;              //default:take photo
int KEY_A_LONG=2;               //default:freeze frame
int KEY_B_SHORT=1;              //default:record
int KEY_B_LONG=3;               //default:manual wb

char ahandle = 1;

//======================================================================================================================
//自动白平衡
//======================================================================================================================
void on_pushButton_Awb_clicked()
{
    ahandle = 1;
 
    int CAMERA_MODLE, Rgain,GRgain,GBgain,Bgain;
    CAMERA_MODLE =   GetIniKeyInt("Option","camera",    PARAM_FILE); //摄像头类型切换1=OV426  0=OH01A  DVP & MIPI

    //2023-05-25  区分不同的摄像头进行AWB======================================================
    //Rgain        =   GetIniKeyInt("isp","awb_grgain",   PARAM_FILE);
    //GRgain       =   GetIniKeyInt("isp","awb_gbgain",   PARAM_FILE);
    //GBgain       =   GetIniKeyInt("isp","awb_rgain",    PARAM_FILE);//此处由280改为350，防止图像偏红--edwin
    //Bgain        =   GetIniKeyInt("isp","awb_bgain",    PARAM_FILE);
    //mppIspAwb(0,2,5500,Rgain,GRgain,GBgain,Bgain);

    if(CAMERA_MODLE==1) //ov426
    {
        Rgain        =   GetIniKeyInt("isp","sdawb_grgain",   PARAM_FILE);
        GRgain       =   GetIniKeyInt("isp","sdawb_gbgain",   PARAM_FILE);
        GBgain       =   GetIniKeyInt("isp","sdawb_rgain",    PARAM_FILE);
        Bgain        =   GetIniKeyInt("isp","sdawb_bgain",    PARAM_FILE); 
        mppIspAwb(0,2,5500,Rgain,GRgain,GBgain,Bgain);
    }
    if(CAMERA_MODLE==0) //os01a
    {
        Rgain        =   GetIniKeyInt("isp","hdawb_grgain",   PARAM_FILE);
        GRgain       =   GetIniKeyInt("isp","hdawb_gbgain",   PARAM_FILE);
        GBgain       =   GetIniKeyInt("isp","hdawb_rgain",    PARAM_FILE);
        Bgain        =   GetIniKeyInt("isp","hdawb_bgain",    PARAM_FILE); 
        mppIspAwb(0,2,5500,Rgain,GRgain,GBgain,Bgain);
    }
}

char vhandle = 0;
//======================================================================================================================
//拍照图标处理函数
//======================================================================================================================
void *  camera_Photo(void *para)
{
    int data =0;
    int id = * (int *)para;
    while(1)
    {
        data = OSA_MSG_Get(id);
        printf("take phot,%d\n",data);
        if(!vhandle)
        {
            if(!noFreeRoom_flag)
            {
                camera_save_photo_slot(m_save_load.pic_load);
                usleep(300000);
            }
        }
    }
}

//======================================================================================================================
//录像图标处理函数
//======================================================================================================================
void * camera_Video(void *para)
{
    int data =0;
    int id = * (int *)para;
    while(1)
    {
        data = OSA_MSG_Get(id);
        printf("take video,%d\n",data);
        if(!noFreeRoom_flag)
        {
            vhandle = !vhandle;
            camera_save_video_slot(m_save_load.avi_load);
        }
    }
}

//=================================================================================================================================================
//初始化相关配置数据
//=================================================================================================================================================
void mainwindow_init()
{
    OSA_MSG_Init_One(OSA_PHOTO,camera_Photo);
    OSA_MSG_Init_One(OSA_VIDEO,camera_Video);
    if(!file_exist(LOCAL_FILE_PIC_LOAD)) mkdirs(LOCAL_FILE_PIC_LOAD);
    if(!file_exist(LOCAL_FILE_AVI_LOAD)) mkdirs(LOCAL_FILE_AVI_LOAD);

    //int saveload = GetIniKeyInt("Option","Savepath",PARAM_FILE);
    int saveload = 0;    //强制保存到本地: //2023-06-02,按录像时重启问题,原因是读取不"Savepath"参数,找不到保存图片和视频的路径.导致保存路径为"NULL"

    if(saveload == 0)                                                  //存储到 :本地
    {
        m_save_load.pic_load = LOCAL_FILE_PIC_LOAD;
        m_save_load.avi_load = LOCAL_FILE_AVI_LOAD;
    }
    else if(saveload == 1)                                             //存储到 :SD卡
    {
        if(!file_exist(SDCARD_FILE_PIC_LOAD)) mkdirs(SDCARD_FILE_PIC_LOAD);
        if(!file_exist(SDCARD_FILE_AVI_LOAD)) mkdirs(SDCARD_FILE_AVI_LOAD);
        m_save_load.pic_load = SDCARD_FILE_PIC_LOAD;
        m_save_load.avi_load = SDCARD_FILE_AVI_LOAD;
        system("mount /dev/mmcblk1p1 /sdcard/");                       //挂载sd卡到系统目录
    }
    else if(saveload == 2)                                             //存储到 :U盘
    {
        if(!file_exist(UDISK_FILE_PIC_LOAD)) mkdirs(UDISK_FILE_PIC_LOAD);
        if(!file_exist(UDISK_FILE_AVI_LOAD)) mkdirs(UDISK_FILE_AVI_LOAD);
        m_save_load.pic_load = UDISK_FILE_PIC_LOAD;
        m_save_load.avi_load = UDISK_FILE_AVI_LOAD;
        system("mount /dev/sda1 /udisk/");                                 //挂载USB到系统目录
    }
    printf("INFO::PICTURE SAVE ::%s\r\n",m_save_load.pic_load);
    printf("INFO::VIDEO   SAVE ::%s\r\n",m_save_load.avi_load);

    //================================ISP parameter==========================================
    CAMERA_MODLE      = GetIniKeyInt("Option","camera",PARAM_FILE);                  //摄像头类型切换1=OV426  0=OH01A  DVP & MIPI
    ae_mode           = GetIniKeyInt("isp","ae_mold",PARAM_FILE);       			 //曝光模式设置：ae_mode =0 OP_TYPE_AUTO;ae_mode=1 OP_TYPE_MANUAL;ae_mode=2 bByPass;
    backlight_value   = GetIniKeyInt("isp","Backlight",PARAM_FILE);       	         //背光亮度
    ae_exposure       = GetIniKeyInt("isp","ae_exposure",PARAM_FILE);      	         //自动曝光最大时间
    ae_again          = GetIniKeyInt("isp","ae_again",PARAM_FILE);       	         //自动曝光最大again
    ae_dgain          = GetIniKeyInt("isp","ae_dgain",PARAM_FILE);       	         //自动曝光最大dgain
    ae_ispdgain       = GetIniKeyInt("isp","ae_ispdgain",PARAM_FILE);                //自动曝光最大ispdgain
    awb_awbmode       = GetIniKeyInt("isp","awb_awbmode",PARAM_FILE);                //白平衡模式
    awb_temperature   = GetIniKeyInt("isp","awb_temperature",PARAM_FILE);            //色温

    //
    //awb_rgain         = GetIniKeyInt("isp","awb_rgain",PARAM_FILE);                 //白平衡rgain
    //awb_grgain        = GetIniKeyInt("isp","awb_grgain",PARAM_FILE);                //白平衡grgain
    //awb_gbgain        = GetIniKeyInt("isp","awb_gbgain",PARAM_FILE);                //白平衡gbgain
    //awb_bgain         = GetIniKeyInt("isp","awb_bgain",PARAM_FILE);                 //白平衡bgain
    //csc_brightness    = GetIniKeyInt("isp","csc_brightness",PARAM_FILE);            //亮度
    //csc_constrast     = GetIniKeyInt("isp","csc_constrast",PARAM_FILE);             //对比度
    //csc_hue           = GetIniKeyInt("isp","csc_hue",PARAM_FILE);       	          //色域值
    //csc_saturation    = GetIniKeyInt("isp","csc_saturation",PARAM_FILE);            //饱和度

    if(CAMERA_MODLE==1) //OV426
    {
        awb_rgain         = GetIniKeyInt("isp","sdawb_rgain",PARAM_FILE);                 //白平衡rgain
        awb_grgain        = GetIniKeyInt("isp","sdawb_grgain",PARAM_FILE);                //白平衡grgain
        awb_gbgain        = GetIniKeyInt("isp","sdawb_gbgain",PARAM_FILE);                //白平衡gbgain
        awb_bgain         = GetIniKeyInt("isp","sdawb_bgain",PARAM_FILE);                 //白平衡bgain
        csc_brightness    = GetIniKeyInt("isp","sdcsc_brightness",PARAM_FILE);            //亮度
        csc_constrast     = GetIniKeyInt("isp","sdcsc_constrast",PARAM_FILE);             //对比度
        csc_hue           = GetIniKeyInt("isp","sdcsc_hue",PARAM_FILE);                   //色域值
        csc_saturation    = GetIniKeyInt("isp","sdcsc_saturation",PARAM_FILE);            //饱和度 
    }
    if(CAMERA_MODLE==0) //OS01A
    {
        awb_rgain         = GetIniKeyInt("isp","hdawb_rgain",PARAM_FILE);                 //白平衡rgain
        awb_grgain        = GetIniKeyInt("isp","hdawb_grgain",PARAM_FILE);                //白平衡grgain
        awb_gbgain        = GetIniKeyInt("isp","hdawb_gbgain",PARAM_FILE);                //白平衡gbgain
        awb_bgain         = GetIniKeyInt("isp","hdawb_bgain",PARAM_FILE);                 //白平衡bgain
        csc_brightness    = GetIniKeyInt("isp","hdcsc_brightness",PARAM_FILE);            //亮度
        csc_constrast     = GetIniKeyInt("isp","hdcsc_constrast",PARAM_FILE);             //对比度
        csc_hue           = GetIniKeyInt("isp","hdcsc_hue",PARAM_FILE);                   //色域值
        csc_saturation    = GetIniKeyInt("isp","hdcsc_saturation",PARAM_FILE);            //饱和度
    }

    sharp_mode        = GetIniKeyInt("isp","sharp_mode",PARAM_FILE);       	        //锐化模式
    sharp_texturefreq = GetIniKeyInt("isp","sharp_texturefreq",PARAM_FILE);         //细节纹理增强
    sharp_edgefreq    = GetIniKeyInt("isp","sharp_edgefreq",PARAM_FILE);            //边缘增强
    sharp_overshoot   = GetIniKeyInt("isp","sharp_overshoot",PARAM_FILE);           //白点强度
    sharp_undershoot  = GetIniKeyInt("isp","sharp_undershoot",PARAM_FILE);          //黑点强度
    DPC_BlendRatio    = GetIniKeyInt("isp","DPC_blendratio",PARAM_FILE);            //动态坏点校正比率,取值范围[0x0, 0x80]
    DPC_Strength      = GetIniKeyInt("isp","DPC_strength",PARAM_FILE);              //动态坏点校正强度,取值范围[0x0, 0xFF]
    DE_enable         = GetIniKeyInt("isp","DE_enable",PARAM_FILE);
    DE_model          = GetIniKeyInt("isp","DE_mode",PARAM_FILE);
    DE_GlobaGain      = GetIniKeyInt("isp","DE_GlobaGain",PARAM_FILE);               //噪点碎化
    DE_GainLF         = GetIniKeyInt("isp","DE_GainLF",PARAM_FILE);                  //噪点碎化
    DE_GainHF         = GetIniKeyInt("isp","DE_GainHF",PARAM_FILE);                  //噪点碎化
    LDCI_en           = GetIniKeyInt("isp","LDCI_enable",PARAM_FILE);
    LDCI_mode         = GetIniKeyInt("isp","LDCI_mode",PARAM_FILE);
    LDCI_LPFSigma     = GetIniKeyInt("isp","LDCI_LPFSigma",PARAM_FILE);              //0-256
    LDCI_Blc          = GetIniKeyInt("isp","LDCI_Blc",PARAM_FILE);                   //0-512
    LDCI_posmean      = GetIniKeyInt("isp","LDCI_posmean",PARAM_FILE);
    LDCI_possigma     = GetIniKeyInt("isp","LDCI_possigma",PARAM_FILE);
    LDCI_poswgt       = GetIniKeyInt("isp","LDCI_poswgt",PARAM_FILE);
    LDCI_negmean      = GetIniKeyInt("isp","LDCI_negmean",PARAM_FILE);
    LDCI_negsigma     = GetIniKeyInt("isp","LDCI_negsigma",PARAM_FILE);
    LDCI_negwgt       = GetIniKeyInt("isp","LDCI_negwgt",PARAM_FILE);
    KEY_AL            = GetIniKeyInt("key","key_A_long",PARAM_FILE);                 //A键 长按
    KEY_AS            = GetIniKeyInt("key","key_A_short",PARAM_FILE);                //A键 短按
    KEY_BL            = GetIniKeyInt("key","key_B_long",PARAM_FILE);                 //B键 长按
    KEY_BS            = GetIniKeyInt("key","key_B_short",PARAM_FILE);                //B键 短按
    HDMI_OUT          = GetIniKeyInt("Option","Size",PARAM_FILE);                    //HDMI输出尺寸  
    CAM_CHANGE_EN     = GetIniKeyInt("Option","Cam_changen",PARAM_FILE);             //是否使能 摄像头类型切换
    save_value        = GetIniKeyInt("Option","Savepath",PARAM_FILE);                //Savepath “图片”和视频保存路径的参数
    sample            = GetIniKeyInt("Option","sample",PARAM_FILE);                  //OV426采样模式
    led_status        = GetIniKeyInt("Option","led_status",PARAM_FILE);              //LED开关状态
    led_value         = GetIniKeyInt("Option","led_value",PARAM_FILE);               //LED档位
    //=========================================================================================
    if(KEY_AS != PARAM_NO_EXIST_PARAM)
    {
        KEY_A_SHORT = GetIniKeyInt("key","key_A_short",PARAM_FILE);                 //A键短按
        KEY_B_SHORT = GetIniKeyInt("key","key_B_short",PARAM_FILE);                 //B键短按
        KEY_A_LONG  = GetIniKeyInt("key","key_A_long",PARAM_FILE);                  //A键长按
        KEY_B_LONG  = GetIniKeyInt("key","key_B_long",PARAM_FILE);                  //B键长按
    }
    else
    {
        PutIniKeyInt("key","key_A_short",0,PARAM_FILE);                             //0 拍照
        PutIniKeyInt("key","key_B_short",1,PARAM_FILE);                             //1 录像
        PutIniKeyInt("key","key_A_long",2,PARAM_FILE);                              //2 冻结
        PutIniKeyInt("key","key_B_long",3,PARAM_FILE);                              //3 手动白平衡
    }
    if( GetIniKeyInt("Option","Led_init",PARAM_FILE) != PARAM_NO_EXIST_PARAM)
    {
        init_led = GetIniKeyInt("Option","Led_init",PARAM_FILE);                    //LED灯初始亮度
        step_led = GetIniKeyInt("Option","led_step",PARAM_FILE);                    //LED灯亮度调节幅度
        led_status = GetIniKeyInt("Option","led_status",PARAM_FILE);
    }
    else
    {
        PutIniKeyInt("Option","Led_init",0,PARAM_FILE);
        PutIniKeyInt("Option","led_step",0,PARAM_FILE);
    }
    if(GetIniKeyInt("Option","camera",PARAM_FILE) != PARAM_NO_EXIST_PARAM)          //判断“Option/camera”  “建”是否存在 “值”
        camera_type =  GetIniKeyInt("Option","camera",PARAM_FILE);                  //如果“Option/camera”   有“值” 则进行赋值；
   
    current_set(led_value,  led_status);                                            //LED初始化函数

    printf("INFO::CAMERA_MODLE = %d;\r\n",CAMERA_MODLE);
    printf("INFO::mainwindow_init Done !!\n");
}

//=================================================================================================================================================
//Save OSD parameter
//=================================================================================================================================================
void save_parameter(int key,char * id,char * idx,int value)
{
    // if(key == 0b000000100)
    PutIniKeyInt(id,idx,value,PARAM_FILE);
}

//=================================================================================================================================================
//key logic   [OSD菜单逻辑功能实现]
//=================================================================================================================================================
void mawinwindow_proc(int key)
{
    if(key > 0b000010000)
        return ;
    switch(global_osd_info.main_id)
    {
        case 1://图像设置
            switch(global_osd_info.mid_id)      
            {
                case 1://global_osd_info.sub_value //图像R分量
                    if(global_osd_info.connect_device==1)       //OV426
                        save_parameter(key,"isp","sdawb_rgain",         global_osd_info.image_set.r);
                    if(global_osd_info.connect_device==2)       //OS01A
                        save_parameter(key,"isp","hdawb_rgain",         global_osd_info.image_set.r);                   
                    mppIspAwb(0,2,global_osd_info.image_set.temperature,global_osd_info.image_set.r,global_osd_info.image_set.g,global_osd_info.image_set.g,global_osd_info.image_set.b);
                    break;

                case 2://global_osd_info.sub_value //图像G分量
                    if(global_osd_info.connect_device==1)       //OV426
                        save_parameter(key,"isp","sdawb_grgain",         global_osd_info.image_set.g);
                    if(global_osd_info.connect_device==2)       //OS01A
                        save_parameter(key,"isp","hdawb_grgain",         global_osd_info.image_set.g);                      
                    mppIspAwb(0,2,global_osd_info.image_set.temperature,global_osd_info.image_set.r,global_osd_info.image_set.g,global_osd_info.image_set.g,global_osd_info.image_set.b);
                    break;

                case 3://global_osd_info.sub_value //图像B分量
                    if(global_osd_info.connect_device==1)       //OV426
                        save_parameter(key,"isp","sdawb_bgain",         global_osd_info.image_set.b);
                    if(global_osd_info.connect_device==2)       //OS01A
                        save_parameter(key,"isp","hdawb_bgain",         global_osd_info.image_set.b);
                    mppIspAwb(0,2,global_osd_info.image_set.temperature,global_osd_info.image_set.r,global_osd_info.image_set.g,global_osd_info.image_set.g,global_osd_info.image_set.b);
                    break;

                case 4://global_osd_info.sub_value //图像增强
                    mppisp_VO_VideoLayerCSC(2,global_osd_info.image_set.enhance);
                    if(global_osd_info.connect_device==1)       //OV426
                        save_parameter(key,"isp","sdcsc_hue",   global_osd_info.image_set.enhance);
                    if(global_osd_info.connect_device==2)       //OS01A
                        save_parameter(key,"isp","hdcsc_hue",   global_osd_info.image_set.enhance);

                    // texturefreq_change();   //细节增强
                    // edgefreq_change();      //边沿增强
                    // overshoot_change();     //白点增强
                    // undershoot_change();    //黑点增强
                    break;

                case 5://global_osd_info.sub_value 图像亮度
                    mppisp_VO_VideoLayerCSC(0,global_osd_info.image_set.brightness);
                    if(global_osd_info.connect_device==1)       //OV426
                        save_parameter(key,"isp","sdcsc_brightness",global_osd_info.image_set.brightness);
                    if(global_osd_info.connect_device==2)       //OS01A
                        save_parameter(key,"isp","hdcsc_brightness",global_osd_info.image_set.brightness);
                    break;

                case 6://global_osd_info.sub_value //图像饱和度
                    mppisp_VO_VideoLayerCSC(3,global_osd_info.image_set.saturate);
                    //mppIspCscManual(0, 3, tmp_saturation);    //饱和度
                    if(global_osd_info.connect_device==1)       //OV426
                        save_parameter(key,"isp","sdcsc_saturation",  global_osd_info.image_set.saturate);
                    if(global_osd_info.connect_device==2)       //OS01A
                        save_parameter(key,"isp","hdcsc_saturation",  global_osd_info.image_set.saturate);
                    break;

                case 7://global_osd_info.sub_value //图像对比度
                    mppisp_VO_VideoLayerCSC(1,global_osd_info.image_set.contrast);
                    //mppIspCscManual(0, 1, tmp_constrast); //对比度
                    if(global_osd_info.connect_device==1)       //OV426
                        save_parameter(key,"isp","sdcsc_constrast",  global_osd_info.image_set.contrast);
                    if(global_osd_info.connect_device==2)       //OS01A
                        save_parameter(key,"isp","hdcsc_constrast",  global_osd_info.image_set.contrast);
                    break;

                default:
                    break;
            }
            break;

        case 2://图像风格
            switch(global_osd_info.mid_id)
            {

                case 1://圆角
                case 2://直角
                case 3://锐角
                case 4://圆形
                    RC_mask(ucguiBuf,global_osd_info.mask_mode -1);
                break;
                case 5:
                    mppFrameRotate(global_osd_info.rote_mode);
                break;
                case 6:
                    mppFrameMirror(global_osd_info.mirror_mode);
                break;
            }
            save_parameter(key,"Option","Mask",               global_osd_info.mask_mode);
            save_parameter(key,"Option","Rotate",             global_osd_info.rote_mode);
            save_parameter(key,"Option","Mirror",             global_osd_info.mirror_mode);
            break;

        case 3://图像缩放
            if(global_osd_info.main_select)
            {
                PutIniKeyInt("Option","Size", global_osd_info.scale_mode,PARAM_FILE);
                mppFrameScale();
                RC_mask(ucguiBuf,global_osd_info.mask_mode -1);
                global_osd_info.scale_mode = read_osd_parameter_key("Option", "Size", 3);
            }
            break;

        case 4://照明设置
            switch(global_osd_info.mid_id)
            {
                case 1://global_osd_info.sub_value 开启关闭

                    //int current_set(int level,int openflag);level亮度等级,openflag=0关闭,1开启;

                    //current_set(global_osd_info.led_level.led_status, global_osd_info.led_level.led_status);
                    current_set(global_osd_info.led_level.led_value,  global_osd_info.led_level.led_status);
                    save_parameter(key,"Option","led_status",         global_osd_info.led_level.led_status);
                    break;
                
                case 2://global_osd_info.sub_value 亮度等级
                    //current_set(global_osd_info.led_level.led_value,  global_osd_info.led_level.led_value);  //IIC写入
                    current_set(global_osd_info.led_level.led_value,  global_osd_info.led_level.led_status);  //IIC写入
                    save_parameter(key,"Option","led_value",          global_osd_info.led_level.led_value);
                    break;
                
                default:
                    break;
            }
            break;

        case 5://连接设备
            PutIniKeyInt("Option","connect_device",      global_osd_info.connect_device,PARAM_FILE);
            if(global_osd_info.main_select)
                mppSensorChange(global_osd_info.connect_device);
            PutIniKeyInt("Option","connect_device",      global_osd_info.connect_device,PARAM_FILE);

            //2023-05-25 同步更新camera参数
            if(global_osd_info.connect_device==2)
                PutIniKeyInt("Option","camera",0,PARAM_FILE);   //camera 摄像头类型切换 0=OH01A 
            else 
                PutIniKeyInt("Option","camera",1,PARAM_FILE);   //camera 摄像头类型切换 1=OV426 

            // save_parameter(key,"Option","connect_device",      global_osd_info.connect_device);
            break;

        case 6://显示设置
            // mppChangeVo(&stVoConfig,global_osd_info.scale_mode - 1);
            PutIniKeyInt("Option","display_set",      global_osd_info.display_set,PARAM_FILE);
            if(global_osd_info.main_select)
                mppDisplaySet(global_osd_info.display_set);
            save_parameter(key,"Option","display_set",         global_osd_info.display_set);
            break;

        case 7://时间设置
            save_time();
            break;

        case 8://系统设置
            switch(global_osd_info.mid_id)
            {
                case 1://系统复位
                    if(key == KEY_OK_VALUE)
                        VSB_osd_parameter_default();
                    save_parameter(key,"Option","system_reset",        global_osd_info.system_set.system_reset);
                    printf("%s,%d\n",__func__,__LINE__);
                    break;
                case 2://软件升级
                    save_parameter(key,"Option","software_upgrade",    global_osd_info.system_set.software_upgrade);
                    printf("%s,%d\n",__func__,__LINE__);
                    break;
                case 3://global_osd_info.sub_value 语言切换
                    save_parameter(key,"Option","language",            global_osd_info.system_set.language);
                    break;
            }
            break;
    }
}

//=================================================================================================================================================
// osd-Thread
//=================================================================================================================================================
int OSD_ON_OFF = 0;
void * mainwindow_proc_thread(void *pArgs)
{
    //printf("INFO::(0x%lx): mainwindow_proc_thread\n",pthread_self());     //打印线程

    unsigned char key;
    while(1)
    {
        if(queue_size(&key_queue))
        {
            key = queue_pop(&key_queue);
            switch (key)
            {
                case 0b00000001://上翻
                case 0b00000010://下翻
                case 0b00000100://向左
                case 0b00001000://向右
                case 0b00010000://确认
                    if(OSD_ON_OFF)
                        osd_process(key);
                break;
                case 0b00100000://打开关闭OSD
                    OSD_ON_OFF = !OSD_ON_OFF;
                    if(OSD_ON_OFF)
                    {
                        VSB_osd_init();
                        osd_process(key);
                    }
                    else
                        VSB_osd_exit();
                break;
                default:
                break;
            }
            mawinwindow_proc(key);
            VSB_osd_flush_cache(&osd_mutex);
        }
        usleep(10000);
    }
}



//=================================================================================================================================================
//更新时间及刷新
//=================================================================================================================================================
void * timerUpdate(void *pArgs)
{
    //printf("INFO::(0x%lx): timerUpdate\n",pthread_self());                        //打印线程

    while(1)
    {
        if(!OSD_ON_OFF)
        {
            VSB_osd_update();                                                        //更新OSD文字信息非menu
            read_osd_parameter();                                                    //读取OSD到配置参数
            VSB_osd_flush_cache(&osd_mutex);                                         //osd_mutex互斥锁
           //printf("INFO::Mainwindow_thread timerUpdate   local = 2;\r\n");
        }
        usleep(500000);
    }

    //===========================================================================================================================================
    //******************************************************此处" while(1) "没法执行到*************************************************************
    // 实际控制的函数是:camera_thread.c中的:void mppisp_ov426_ctrl() 和 void mppisp_os01a_ctrl();
    //===========================================================================================================================================
    while(1)
    {

        //printf("INFO::Mainwindow_thread timerUpdate   local = 3;\r\n");
        //AE=======================================================================================================
        int tmp_exposure      = GetIniKeyInt("isp","ae_exposure",PARAM_FILE);         //5000-1000000 def=30000;
        int tmp_again         = GetIniKeyInt("isp","ae_again",PARAM_FILE);            //1024-20480,def=2048;
        int tmp_dgain         = GetIniKeyInt("isp","ae_dgain",PARAM_FILE);            //1024-20480,def=2048;
        int tmp_ispdgain      = GetIniKeyInt("isp","ae_ispdgain",PARAM_FILE);         //1024-20480,def=2048;

        //CSC======================================================================================================
        //awb======================================================================================================
        int tmp_awbmode       = GetIniKeyInt("isp","awb_awbmode",PARAM_FILE);         // 0:Auto  1: calgainByTemp  2:MWB
        int tmp_temperature   = GetIniKeyInt("isp","awb_temperature",PARAM_FILE);     //5500

        int tmp_rgain,tmp_grgain,tmp_gbgain,tmp_bgain;
        if(CAMERA_MODLE==1) //ov426
        {
            tmp_rgain         = GetIniKeyInt("isp","sdawb_rgain",PARAM_FILE);           //1000
            tmp_grgain        = GetIniKeyInt("isp","sdawb_grgain",PARAM_FILE);          //1000
            tmp_gbgain        = GetIniKeyInt("isp","sdawb_gbgain",PARAM_FILE);          //1000
            tmp_bgain         = GetIniKeyInt("isp","sdawb_bgain",PARAM_FILE);           //1000
        }
        if(CAMERA_MODLE==0) //os01a
        {
            tmp_rgain         = GetIniKeyInt("isp","hdawb_rgain",PARAM_FILE);           //1000
            tmp_grgain        = GetIniKeyInt("isp","hdawb_grgain",PARAM_FILE);          //1000
            tmp_gbgain        = GetIniKeyInt("isp","hdawb_gbgain",PARAM_FILE);          //1000
            tmp_bgain         = GetIniKeyInt("isp","hdawb_bgain",PARAM_FILE);           //1000 
        }
        //int tmp_rgain         = GetIniKeyInt("isp","awb_rgain",PARAM_FILE);           //1000
        //int tmp_grgain        = GetIniKeyInt("isp","awb_grgain",PARAM_FILE);          //1000
        //int tmp_gbgain        = GetIniKeyInt("isp","awb_gbgain",PARAM_FILE);          //1000
        //int tmp_bgain         = GetIniKeyInt("isp","awb_bgain",PARAM_FILE);           //1000

        //SHARPEN===================================================================================================
        int tmp_sharpmode     = GetIniKeyInt("isp","sharp_mode",PARAM_FILE);          //0:auto,1:menu 2:menu_all
        int tmp_texturefreq   = GetIniKeyInt("isp","sharp_texturefreq",PARAM_FILE);   //(128)   1000
        int tmp_edgefreq      = GetIniKeyInt("isp","sharp_edgefreq",PARAM_FILE);      //(96)    2000
        int tmp_overshoot     = GetIniKeyInt("isp","sharp_overshoot",PARAM_FILE);     //(100)   12
        int tmp_undershoot    = GetIniKeyInt("isp","sharp_undershoot",PARAM_FILE);    //(127)   20
        int tmp_umax          = GetIniKeyInt("isp","sharp_umax",PARAM_FILE);          //225
        int tmp_umin          = GetIniKeyInt("isp","sharp_umin",PARAM_FILE);          //0
        int tmp_vmax          = GetIniKeyInt("isp","sharp_vmax",PARAM_FILE);          //225
        int tmp_vmin          = GetIniKeyInt("isp","sharp_vmin",PARAM_FILE);          //0
        int tmp_luma          = GetIniKeyInt("isp","sharp_luma",PARAM_FILE);          //(127)
        int tmp_texturestr    = GetIniKeyInt("isp","sharp_texturestr",PARAM_FILE);    //(300)
        int tmp_edgestr       = GetIniKeyInt("isp","sharp_edgestr",PARAM_FILE);       //(400)
        int tmp_supstr        = GetIniKeyInt("isp","sharp_supstr",PARAM_FILE);        //8
        int tmp_supadj        = GetIniKeyInt("isp","sharp_supadj",PARAM_FILE);        //9
        int tmp_detailctrl    = GetIniKeyInt("isp","sharp_dectrl",PARAM_FILE);        //128
        int tmp_detailctrlthr = GetIniKeyInt("isp","sharp_dectrlthr",PARAM_FILE);     //160
        int tmp_edgefilt      = GetIniKeyInt("isp","sharp_edgefilt",PARAM_FILE);      //53
        int tmp_srgain        = GetIniKeyInt("isp","sharp_srgain",PARAM_FILE);	      //28
        int tmp_sggain        = GetIniKeyInt("isp","sharp_sggain",PARAM_FILE);	      //32
        int tmp_sbgain        = GetIniKeyInt("isp","sharp_sbgain",PARAM_FILE);	      //28
        int tmp_skingain      = GetIniKeyInt("isp","sharp_skingain",PARAM_FILE);      //23
        int tmp_maxsharp      = GetIniKeyInt("isp","sharp_maxsharp",PARAM_FILE);      //160

        //========================================================================================================
        //GAMMA
        int tmp_gammadisable  = GetIniKeyInt("isp","gamma_disable",PARAM_FILE);       //0 HI_TRUE
        int tmp_gammamode     = GetIniKeyInt("isp","gamma_mode",PARAM_FILE);          //0 ISP_GAMMA_CURVE_DEFAULT
        //========================================================================================================
        //CCM
        int tmp_ccmmode       = GetIniKeyInt("isp","ccm_mode",PARAM_FILE);            //0:auto
        //========================================================================================================
        //色彩校正矩阵
        HI_U16 tmp_ccmmatrix[9];
        tmp_ccmmatrix[0]      = GetIniKeyInt("isp","ccm_rr",PARAM_FILE);              //465
        tmp_ccmmatrix[1]      = GetIniKeyInt("isp","ccm_rg",PARAM_FILE);              //32984
        tmp_ccmmatrix[2]      = GetIniKeyInt("isp","ccm_rb",PARAM_FILE);              //32775
        tmp_ccmmatrix[3]      = GetIniKeyInt("isp","ccm_gr",PARAM_FILE);              //32832
        tmp_ccmmatrix[4]      = GetIniKeyInt("isp","ccm_gg",PARAM_FILE);              //449
        tmp_ccmmatrix[5]      = GetIniKeyInt("isp","ccm_gb",PARAM_FILE);              //32897
        tmp_ccmmatrix[6]      = GetIniKeyInt("isp","ccm_br",PARAM_FILE);              //1
        tmp_ccmmatrix[7]      = GetIniKeyInt("isp","ccm_bg",PARAM_FILE);              //32959
        tmp_ccmmatrix[8]      = GetIniKeyInt("isp","ccm_bb",PARAM_FILE);              //446


        //CAMERA_MODLE 1=OV426  0=OH01A
        //sensorId     1=OV426  0=OH01A

        CAMERA_MODLE    = GetIniKeyInt("Option","camera",    PARAM_FILE); //摄像头类型切换1=OV426  0=OH01A  DVP & MIPI
        printf("INFO::CAMERA_MODLE = %d;\r\n",CAMERA_MODLE);
        //if(CAMERA_MODLE == 1 || sensorId == 1)
        if(CAMERA_MODLE == 1)
        {

            //=======================================================================================================
            //自动曝光属性设置：ae_mode =0 OP_TYPE_AUTO;       ae_mode=1 OP_TYPE_MANUAL;     ae_mode=2 bByPass;
            //=======================================================================================================
            PutIniKeyInt("isp","ae_mode",   2,    PARAM_FILE);                      //2 =bypass.
            ae_mode = GetIniKeyInt("isp",   "ae_mode", PARAM_FILE);
            mppIsp_AUTO_EXPOSURE(0,ae_mode);                                        //OP_TYPE_AUTO
            //mppIspAEDisable();                                                    //关闭自动曝光
     
            //手动曝光模式--------------------------------------------------------
            //if(ae_mode)
            //{
            //    mppIspAeManual(0, 0,OP_TYPE_MANUAL, tmp_exposure);
            //    mppIspAeManual(0, 1,OP_TYPE_MANUAL, tmp_again);
            //    mppIspAeManual(0, 2,OP_TYPE_MANUAL, tmp_dgain);
            //    mppIspAeManual(0, 3,OP_TYPE_MANUAL, tmp_ispdgain);
            //}

            //Set AWB  tmp_awbmode  0:Auto   1: calgainByTemp  2:MWB
            mppIspAwb(0,tmp_awbmode,tmp_temperature,tmp_rgain,tmp_grgain,tmp_gbgain,tmp_bgain);

            //Set Sharpen
            mppIspSharpen(0,  tmp_sharpmode,  tmp_texturefreq,tmp_edgefreq,tmp_overshoot,tmp_undershoot,
            tmp_umax,tmp_umin,tmp_vmax,tmp_vmin,tmp_luma,tmp_texturestr,tmp_edgestr,tmp_supstr,
            tmp_supadj,tmp_detailctrl,tmp_detailctrlthr,tmp_edgefilt,tmp_srgain,tmp_sggain,tmp_sbgain,
            tmp_skingain,tmp_maxsharp);

            //Set Gamma  gamma_disable=0 gamma_mode=1
            mppIspGammaCtrl(0,tmp_gammadisable,tmp_gammamode);//gamma设置，0默认 1SRGB 2HDR(3516用不了)
            mppIspCcmCtrl(0,tmp_ccmmode,tmp_ccmmatrix);

            //降噪设置  Bayer NR
            ISP_NR_ATTR_S stNRAttr;
            HI_MPI_ISP_GetNRAttr(0, &stNRAttr);
            stNRAttr.bEnable = HI_TRUE;
            stNRAttr.bNrLscEnable = HI_FALSE;
            int tmp_lschr0     = GetIniKeyInt("isp","lsc_hr0",PARAM_FILE);
            int tmp_lschr1     = GetIniKeyInt("isp","lsc_hr1",PARAM_FILE);
            HI_MPI_ISP_SetNRAttr(0,&stNRAttr);

            //镜头阴影校正   需要标定参数 LSC
            //ISP_SHADING_ATTR_S stShadingAttr;
            //HI_MPI_ISP_GetMeshShadingAttr(0, &stShadingAttr);
            //stShadingAttr.u16MeshStr = 0;
            //stShadingAttr.u16BlendRatio = 50;
            //HI_MPI_ISP_SetMeshShadingAttr(0, &stShadingAttr);

            //动态坏点校正
            ISP_DP_DYNAMIC_ATTR_S stDPDynamicAttr;
            HI_MPI_ISP_GetDPDynamicAttr(0,&stDPDynamicAttr);
            stDPDynamicAttr.enOpType = OP_TYPE_MANUAL;
            stDPDynamicAttr.stManual.u16BlendRatio = tmp_lschr0;
            stDPDynamicAttr.stManual.u16Strength = tmp_lschr1;
            HI_MPI_ISP_SetDPDynamicAttr(0,&stDPDynamicAttr);
        }
        else if(CAMERA_MODLE == 2)
        {
            //无论是自动曝光还是手动曝光，曝光时间的单位为微秒(us)，曝光增益的单位为10bit 精度的倍数，即1024代表1倍，2048代表2倍等。
            //=======================================================================================================
            //自动曝光属性设置：ae_mode =0 OP_TYPE_AUTO;       ae_mode=1 OP_TYPE_MANUAL;     ae_mode=2 bByPass;
            //=======================================================================================================
            PutIniKeyInt("isp","ae_mode", 0, PARAM_FILE);             //0=AUTO.
            ae_mode = GetIniKeyInt("isp", "ae_mode", PARAM_FILE);     
            mppIsp_AUTO_EXPOSURE(0,ae_mode);                          //OP_TYPE_AUTO

            //Set AWB  tmp_awbmode  0:Auto   1: calgainByTemp  2:MWB
            mppIspAwb(0,tmp_awbmode,tmp_temperature,tmp_rgain,tmp_grgain,tmp_gbgain,tmp_bgain);

            //Set Sharpen
            mppIspSharpen(0,  tmp_sharpmode,  tmp_texturefreq,tmp_edgefreq,tmp_overshoot,tmp_undershoot,
            tmp_umax,tmp_umin,tmp_vmax,tmp_vmin,tmp_luma,tmp_texturestr,tmp_edgestr,tmp_supstr,
            tmp_supadj,tmp_detailctrl,tmp_detailctrlthr,tmp_edgefilt,tmp_srgain,tmp_sggain,tmp_sbgain,
            tmp_skingain,tmp_maxsharp);

            //Set Gamma  gamma_disable=0 gamma_mode=1------------------------------------------
            mppIspGammaCtrl(0,tmp_gammadisable,tmp_gammamode);      //gamma设置，0默认 1SRGB 2HDR(3516用不了)

            //ISP  CCM  色彩矫正 手动-----------------------------------------------------------------
            mppIspCcmCtrl(0,tmp_ccmmode,tmp_ccmmatrix);

            //降噪设置  Bayer NR
            ISP_NR_ATTR_S stNRAttr;
            HI_MPI_ISP_GetNRAttr(0, &stNRAttr);
            stNRAttr.bEnable = HI_TRUE;                             //使能bayer NR
            stNRAttr.bNrLscEnable = HI_FALSE;
            stNRAttr.enOpType = OP_TYPE_MANUAL;                     //手动降噪模式

			//int tmp_lschr0     = GetIniKeyInt("isp","lsc_hr0",PARAM_FILE);
            //int tmp_lschr1     = GetIniKeyInt("isp","lsc_hr1",PARAM_FILE);
            HI_MPI_ISP_SetNRAttr(0,&stNRAttr);

            //镜头阴影校正   需要标定参数 LSC
            //ISP_SHADING_ATTR_S stShadingAttr;
            //HI_MPI_ISP_GetMeshShadingAttr(0, &stShadingAttr);
            //stShadingAttr.u16MeshStr = 0;
            //stShadingAttr.u16BlendRatio = 50;
            //HI_MPI_ISP_SetMeshShadingAttr(0, &stShadingAttr);

            //动态坏点校正
            ISP_DP_DYNAMIC_ATTR_S stDPDynamicAttr;
            HI_MPI_ISP_GetDPDynamicAttr(0,&stDPDynamicAttr);
            stDPDynamicAttr.enOpType = OP_TYPE_MANUAL;
            stDPDynamicAttr.stManual.u16BlendRatio = DPC_BlendRatio;    //取值范围[0x0, 0x80], 坏点校正过程所需的融合比率, u16BlendRatio 值越大，图像越模糊。
            stDPDynamicAttr.stManual.u16Strength = DPC_Strength;        //取值范围[0x0, 0xFF],无默认值;    ISO越高，对应的u16Strength应该越大，
                                                                        //在图像中坏点校正较好时，图像中偏红严重，此时可以再调节 u16BlendRatio改善图像质量。
            HI_MPI_ISP_SetDPDynamicAttr(0,&stDPDynamicAttr);
        }

        //========================================================================================================
        // OV6946 AND OS01A10
        //========================================================================================================
        //========================================================================================================
        //去 FPN 模块就是要把这些固定模式噪声消除,需要标定黑帧，但是并没有标定,（Fixed Pattern Noise）
        ISP_FPN_ATTR_S pstFPNAttr;
        HI_MPI_ISP_GetFPNAttr(0, &pstFPNAttr);
        pstFPNAttr.bEnable=HI_TRUE;
        pstFPNAttr.enOpType=OP_TYPE_AUTO;
        HI_MPI_ISP_SetFPNAttr(0, &pstFPNAttr);

        //========================================================================================================
        //DE 改善噪声形态， 使得噪声均匀细碎， 同时改善边缘毛糙。
        //========================================================================================================
        mppIspDeCtrl(0,DE_enable,DE_model,DE_GlobaGain,DE_GainLF,DE_GainHF) ;
        //========================================================================================================
        //LDCI 是局域自动对比度增强的简称（Local Dynamic Contrast Improvement）
        //========================================================================================================
        mppIspLdciCtrl(0,LDCI_en,LDCI_mode,LDCI_LPFSigma, LDCI_Blc, LDCI_posmean,LDCI_possigma,LDCI_poswgt, LDCI_negmean,LDCI_negsigma,LDCI_negwgt);
        //========================================================================================================
        //ISP END
        //========================================================================================================

        /*****************KEY FUNCTION**********************/
        KEY_A_SHORT = GetIniKeyInt("key","key_A_short",PARAM_FILE);
        KEY_B_SHORT = GetIniKeyInt("key","key_B_short",PARAM_FILE);
        KEY_A_LONG  = GetIniKeyInt("key","key_A_long",PARAM_FILE);
        KEY_B_LONG  = GetIniKeyInt("key","key_B_long",PARAM_FILE);

        /*********************LED init & step****************/
        init_led    = GetIniKeyInt("Option","Led_init",PARAM_FILE);         //led_init  20230323
        step_led    = GetIniKeyInt("Option","led_step",PARAM_FILE);

		#if 0
		//========================================================================================================
        //Disk Free    存储空间检测
        //========================================================================================================
        QList<QStorageInfo> list = QStorageInfo::mountedVolumes();
        storage = 0,storage_sd = 0,storage_udisk = 0;
        for(QStorageInfo si : list)
        {
            QByteArray ba = si.displayName().toLatin1();
            char *s;
            s = ba.data();
            if(!(strcmp(s,"/video"))) {storage       = si.bytesAvailable()/1024/1024;}   //本地储存空间
            if(!(strcmp(s,"/sdcard"))){storage_sd    = si.bytesAvailable()/1024/1024;}   //SD卡储存空间
            if(!(strcmp(s,"/udisk"))) {storage_udisk = si.bytesAvailable()/1024/1024;}   //U盘储存空间
        }
        QString string = "本地: "+QString::number(storage);
        string+="MB";
        QString string_sd = "SD卡: "+QString::number(storage_sd);
        string_sd+="MB";
        QString string_udisk = "U盘: "+QString::number(storage_udisk);
        string_udisk+="MB";

        ui->label_46->setText(string);
        ui->label_47->setText(string_sd);
        ui->label_48->setText(string_udisk);

        if(strcmp(m_save_load.pic_load,LOCAL_FILE_PIC_LOAD))
            noFreeRoom_flag = storage_sd>10?0:1;
        else
            noFreeRoom_flag = storage>10?0:1;
        if(!startPlayAvi)
        {
            ui->pic_stop_btn->setStyleSheet("border-image: url(:/res/dir/stop.png)");
        }

        if(lightflag)
        {
            FILE* fd;
            char args[60];
            sprintf(args,"/usr/tools/pwm_write 1 %d 0xff 1 >/dev/null",backlight_value);//通过PWM芯片设置背光亮度
            system(args);
            fd = fopen("/etc/backlight","w+");
            fwrite(args,1,45,fd);
            fclose(fd);
            lightflag = 0;
        }

        if(decodeFlag)
        {
            ui->label_2->setText(QString("解码中..."));
            ui->progressBar->setValue(100*decodeFrame/totalFrame);
        }

        if(playFlag)
        {
            if(playFrame == totalFrame)
            {
                ui->label_2->setText(QString("播放完毕"));
                ui->progressBar->setValue(100);
            }
            else
            {
                ui->label_2->setText(QString("播放中..."));
                ui->progressBar->setValue(120*playFrame/totalFrame);
            }
        }
        #endif
        usleep(500000);
    }
}

void * mainwindow_run(void *pArgs)
{
    printf("INFO::(0x%lx): camera_run \n",pthread_self());     //打印线程

    pthread_t tid,tid1,tid2;
    on_pushButton_Awb_clicked();
    mainwindow_init();
    pthread_create(&tid,  0, mainwindow_proc_thread, NULL);
    pthread_create(&tid1, 0, timerUpdate,            NULL);
    pthread_create(&tid2, 0, check_udisk,            NULL);
    printf("INFO::mainwindow Running!!\n");
    while(1)
    {
        usleep(10000);
    }
}

























#if 0
//=================================================================================================================================================
//初始化QT程序控件与事件的连接   信号与槽连接
//=================================================================================================================================================
void initconnect()
{
    /***************文件浏览界面****************************************************************************/
    connect(ui->pic_btn,           SIGNAL(clicked()),this,SLOT(pic_select()));      //文件列表查看图片列表
    connect(ui->video_btn,         SIGNAL(clicked()),this,SLOT(video_select()));    //文件列表查看视频列表
    connect(ui->play_pic_btn,      SIGNAL(clicked()),this,SLOT(play_pic()));        //查看图片
    connect(ui->play_video_btn,    SIGNAL(clicked()),this,SLOT(play_video()));      //查看视频
    connect(ui->delete_btn,        SIGNAL(clicked()),this,SLOT(delete_file()));     //删除文件
    connect(ui->fileview_back_btn, SIGNAL(clicked()),this,SLOT(fileview_back()));   //回到主界面
    connect(ui->pic_front_btn,     SIGNAL(clicked()),this,SLOT(pic_front()));       //上一个文件
    connect(ui->pic_stop_btn,      SIGNAL(clicked()),this,SLOT(pic_stop()));        //播放暂停
    connect(ui->pic_next_btn,      SIGNAL(clicked()),this,SLOT(pic_next()));        //下一个文件
    connect(ui->pic_back_btn,      SIGNAL(clicked()),this,SLOT(pic_back()));        //返回文件列表
    connect(fileListWidget,        SIGNAL(currentRowChanged(int)),this,SLOT(get_selectfile(int)));
    connect(fileListWidget,        SIGNAL(itemDoubleClicked(QListWidgetItem *)),this,SLOT(double_play(QListWidgetItem*)));//双击播放

    /*************8图标主界面********************************************************************************/
    connect(ui->file_manager_btn,  SIGNAL(clicked()),this,SLOT(file_manager()));    //显示文件管理页面
    connect(ui->backlight_btn,     SIGNAL(clicked()),this,SLOT(backlight_set()));   //显示亮度设置界面
    connect(ui->sleeptime_btn,     SIGNAL(clicked()),this,SLOT(sleeptime_set()));   //显示通用设置界面
    connect(ui->adavance_btn,      SIGNAL(clicked()),this,SLOT(adavance_set()));    //显示高级设置界面
    connect(ui->help_btn,          SIGNAL(clicked()),this,SLOT(help()));            //进入图像设置界面
    connect(ui->set_back_btn,      SIGNAL(clicked()),this,SLOT(set_back()));        //返回主界面


    connect(ui->chooseBox_caminput,SIGNAL(currentIndexChanged(int)),this,SLOT(setCamera_input_en(int))); //是否允许摄像头的输入模式切换DVP&MIPI
    //图像设置
    connect(ui->PBT_save_image,    SIGNAL(clicked()),        this,SLOT(image_setting_save()));           //保存设置
    connect(ui->again_btn,         SIGNAL(valueChanged(int)),this,SLOT(again_changed(int)));
    connect(ui->dgain_btn,         SIGNAL(valueChanged(int)),this,SLOT(dgain_changed(int)));
    connect(ui->exposure_btn,      SIGNAL(valueChanged(int)),this,SLOT(exposure_changed(int)));
    connect(ui->ispgain_btn,       SIGNAL(valueChanged(int)),this,SLOT(ispgain_changed(int)));

    //白平衡
    connect(ui->pushButton_save_frame,     SIGNAL(clicked()),this,SLOT(frame_setting_save()));          //保存画面设置
    connect(ui->local_btn_2,       SIGNAL(clicked()),this,SLOT(fice_close()));
    connect(ui->sd_btn_2,          SIGNAL(clicked()),this,SLOT(fice_open()));
    connect(ui->pushButton_awb,    SIGNAL(clicked()),this,SLOT(awbmode_save()));                        //白平衡模式设置保存
    connect(ui->temperature_btn,   SIGNAL(valueChanged(int)),this,SLOT(temperature_change(int)));       //以下是白平衡相关设置随滑动条变化而变化
    //清晰度
    connect(ui->pushButton_sharp,  SIGNAL(clicked()),this,SLOT(sharpmode_save()));                      //锐化模式设置
    connect(ui->chooseBox_sample,  SIGNAL(currentIndexChanged(int)),this,SLOT(CB_sample_Changed(int))); //设置采样模式
    connect(ui->back_2,            SIGNAL(clicked()),this,SLOT(advanced_back()));                       //返回上级菜单
    //图像优化
    connect(ui->LDCI_LPFSigma,     SIGNAL(valueChanged(int)),this,SLOT(LDCI_LPFSigma_change(int)));
    connect(ui->LDCI_Blc,          SIGNAL(valueChanged(int)),this,SLOT(LDCI_Blc_change(int)));
    connect(ui->LDCI_posmean,      SIGNAL(valueChanged(int)),this,SLOT(LDCI_posmean_change(int)));
    connect(ui->LDCI_possigma,     SIGNAL(valueChanged(int)),this,SLOT(LDCI_possigma_change(int)));      //debug ERROR
    connect(ui->LDCI_poswgt,       SIGNAL(valueChanged(int)),this,SLOT(LDCI_poswgt_change(int)));        //debug ERROR
    connect(ui->LDCI_negmean,      SIGNAL(valueChanged(int)),this,SLOT(LDCI_negmean_change(int)));       //debug ERROR
    connect(ui->LDCI_negsigma,     SIGNAL(valueChanged(int)),this,SLOT(LDCI_negsigma_change(int)));      //debug ERROR
    connect(ui->LDCI_negwgt,       SIGNAL(valueChanged(int)),this,SLOT(LDCI_negwgt_change(int)));

    connect(ui->chooseBox_aemold,  SIGNAL(currentIndexChanged(int)),this,SLOT(Set_AEmold_changed())); //曝光模式设置：ae_mode =0 OP_TYPE_AUTO;ae_mode=1 OP_TYPE_MANUAL;ae_mode=2 bByPass;
    connect(ui->chooseBox_dehaze,  SIGNAL(currentIndexChanged(int)),this,SLOT(dehaze_change()));
    connect(ui->chooseBox_denoise, SIGNAL(currentIndexChanged(int)),this,SLOT(denoise_change()));
    connect(ui->chooseBox_LDCIen,  SIGNAL(currentIndexChanged(int)),this,SLOT(LDCIen_change(int)));
    connect(ui->chooseBox_LDCImode,SIGNAL(currentIndexChanged(int)),this,SLOT(LDCImode_change(int)));

    //按键的SIGNAL使用“clicked()”,滑动条的SIGNAL 使用“valueChanged(int)”,下拉框的SIGNAL使用“currentIndexChanged(int)”.

    //======================================================================================================
    // 文件管理界面
    //======================================================================================================
    connect(ui->local_btn,         SIGNAL(clicked()),this,SLOT(localpath_select()));//选择本地储存路径
    connect(ui->sd_btn,            SIGNAL(clicked()),this,SLOT(sdpath_select()));   //选择SD卡储存路径
    connect(ui->usb_btn,           SIGNAL(clicked()),this,SLOT(usbpath_select()));  //选择USB储存路径
    connect(ui->save,              SIGNAL(clicked()),this,SLOT(savepath_confirm()));//保存 储存路径设置
    connect(ui->copy_btn,          SIGNAL(clicked()),this,SLOT(copy_file()));       //复制文件到SD卡
    connect(ui->copy_btn_Udisk,    SIGNAL(clicked()),this,SLOT(copy_file_USB()));   //赋值文件到U盘
    connect(ui->clear_btn,         SIGNAL(clicked()),this,SLOT(clear_file()));      //跳转清除文件界面
    connect(ui->file_manager_back, SIGNAL(clicked()),this,SLOT(filemanager_back()));//返回上级菜单
    connect(ui->delete_confirm_btn,SIGNAL(clicked()),this,SLOT(clearfile_confirm()));//确认删除文件
    connect(ui->delete_cancel_btn, SIGNAL(clicked()),this,SLOT(clearfile_cancel())); //取消删除文件


    //======================================================================================================
    // 通用设置
    //======================================================================================================
    connect(ui->chooseBox_size,    SIGNAL(currentIndexChanged(int)),this,SLOT(change_frame_size(int))); //改变HDMI输出画面大小
    connect(ui->chooseBox_camera,  SIGNAL(currentIndexChanged(int)),this,SLOT(change_camera_type(int)));//设置摄像头类型， 0=DVP,1=MIPI
    connect(ui->lightback,         SIGNAL(clicked()),this,SLOT(sleeptime_back()));                      //返回上级设置
    connect(ui->pushButton_4,      SIGNAL(clicked()),this,SLOT(chargemode_save()));                     //"通用设置”页面的保存

    //======================================================================================================
    // 图像设置
    //======================================================================================================
    connect(ui->help_back_btn,     SIGNAL(clicked()),this,SLOT(help_back()));       //
    connect(ui->brightness_btn,    SIGNAL(valueChanged(int)),this,SLOT(brightness_changed(int)));
    connect(ui->constrast_btn,     SIGNAL(valueChanged(int)),this,SLOT(constrast_changed(int)));
    connect(ui->hue_btn,           SIGNAL(valueChanged(int)),this,SLOT(hue_changed(int)));
    connect(ui->saturastion_btn,   SIGNAL(valueChanged(int)),this,SLOT(saturastion_changed(int)));
    connect(ui->rgain_btn,         SIGNAL(valueChanged(int)),this,SLOT(rgain_change(int)));
    connect(ui->grgain_btn,        SIGNAL(valueChanged(int)),this,SLOT(grgain_change(int)));
    connect(ui->gbgain_btn,        SIGNAL(valueChanged(int)),this,SLOT(gbgain_change(int)));
    connect(ui->bgain_btn,         SIGNAL(valueChanged(int)),this,SLOT(bgain_change(int)));
    connect(ui->texturefreq_btn,   SIGNAL(valueChanged(int)),this,SLOT(texturefreq_change(int)));       //细节增强
    connect(ui->edgefreq_btn,      SIGNAL(valueChanged(int)),this,SLOT(edgefreq_change(int)));          //边沿增强
    connect(ui->overshoot_btn,     SIGNAL(valueChanged(int)),this,SLOT(overshoot_change(int)));         //白点增强
    connect(ui->undershoot_btn,    SIGNAL(valueChanged(int)),this,SLOT(undershoot_change(int)));        //黑点增强

    //======================================================================================================
    // BEEP_TEST
    //======================================================================================================
    connect(ui->pushButton_beep_off, SIGNAL(clicked()),this,SLOT(pushButton_beep_off()));
    connect(ui->pushButton_beep_on,  SIGNAL(clicked()),this,SLOT(pushButton_beep_on()));
    //======================================================================================================
}



//=================================================================================================================================================
//图片视频浏览
//=================================================================================================================================================
void browseform::Show_lode_file(QString dir)
{
    curdir = dir;
    QDir rootDir(dir);
    QStringList stringlist;
    list.clear();
    fileListWidget->clear();
    if(dir.contains("pic")){
       stringlist << QString("*.jpg");
    }else{
        stringlist << QString("*.avi");
    }
    rootDir.setFilter(QDir::Files | QDir::NoSymLinks);//设置类型过滤器，只为文件格式
    rootDir.setNameFilters(stringlist); //设置文件名称过滤器，只为filters格式（后缀为.jpeg等图片格式）
    list = rootDir.entryInfoList(stringlist);
    for (unsigned int i = 0; i < list.count(); i++)
    {
        QFileInfo tmpFileInfo = list.at(i);
        if(tmpFileInfo.fileName().contains(".jpg"))
        {
            QIcon icon("jpg1.png");
            QString fileName = QString("%1.jpg").arg(tmpFileInfo.completeBaseName());
            QListWidgetItem*tmpListWidgetItem = new QListWidgetItem(icon, fileName);
            tmpListWidgetItem->setFont(QFont( "Ubuntu",24,24));
            tmpListWidgetItem->setSizeHint(QSize(FILE_LIST_WIDTH,FILE_LIST_HEIGHT));
            fileListWidget->addItem(tmpListWidgetItem);
        }
        if(tmpFileInfo.fileName().contains(".avi"))
        {
            QIcon icon("avi1.png");
            QString fileName = QString("%1.avi").arg(tmpFileInfo.completeBaseName());
            QListWidgetItem*tmpListWidgetItem = new QListWidgetItem(icon, fileName);
            tmpListWidgetItem->setFont(QFont( "Ubuntu",24,24));
            tmpListWidgetItem->setSizeHint(QSize(FILE_LIST_WIDTH,FILE_LIST_HEIGHT));
            fileListWidget->addItem(tmpListWidgetItem);
        }
    }
    cur_index = 1000000;
}
//=================================================================================================================================================
/* 拷贝文件夹 */
//=================================================================================================================================================
bool browseform::copyDirectoryFiles(const QString &fromDir, const QString &toDir, int days,bool coverFileIfExist)
{
    QDir sourceDir(fromDir);
    QDir targetDir(toDir);
    QDateTime created;
    int curDay = QDateTime::currentDateTime().date().day();
    if(!targetDir.exists()){  /* 如果目标目录不存在，则进行创建 */
            return false;
    }
    QFileInfoList fileInfoList = sourceDir.entryInfoList();
    foreach(QFileInfo fileInfo, fileInfoList){
    if(fileInfo.fileName() == "." || fileInfo.fileName() == "..")
        continue;
        /* 当允许覆盖操作时，将旧文件进行删除操作 */
        if(targetDir.exists(fileInfo.fileName())){
            targetDir.remove(fileInfo.fileName());
        }
       int creatDays = fileInfo.created().date().day();
       if((curDay - creatDays) < days){
             // 进行文件copy
             if(!QFile::copy(fileInfo.filePath(), targetDir.filePath(fileInfo.fileName()))){
                 return false;
             }
             system("sync");
       }
    }
    return true;
}

//=================================================================================================================================================
//删除路径
//=================================================================================================================================================
bool browseform::deleteDir(const QString &path)
{
    if(path.isEmpty())
    {
        return false;
    }
    QDir dir(path);
    if(!dir.exists()){
        return true;
    }
    //设置过滤
    dir.setFilter(QDir::AllEntries | QDir::NoDotAndDotDot);
    // 获取所有的文件信息
    QFileInfoList fileList = dir.entryInfoList();
    //遍历文件信息
    foreach (QFileInfo file, fileList){
        // 是文件，删除
        if (file.isFile()){
            file.dir().remove(file.fileName());
        // 递归删除
        }else{
          //  deleteDir(file.absoluteFilePath());
        }
    }
}

//=================================================================================================================================================
//图片选择
//=================================================================================================================================================
void browseform::pic_select()
{
    ui->pic_btn->setStyleSheet("background-color:blue");
    ui->video_btn->setStyleSheet(0);                        //getName
    lookfiletype = MEDIA_PIC;
    Show_lode_file(m_save_load.pic_load);
}

//=================================================================================================================================================
//视频选择
//=================================================================================================================================================
void browseform::video_select()
{
    ui->pic_btn->setStyleSheet(0);
    ui->video_btn->setStyleSheet("background-color:blue");
    lookfiletype = MEDIA_VIDEO;
    Show_lode_file(m_save_load.avi_load);
}

//=================================================================================================================================================

//=================================================================================================================================================
void browseform::get_selectfile(int currentRow)
{
    cur_index=currentRow;
}

//=================================================================================================================================================
//图片模式隐藏暂停和播放按钮
//=================================================================================================================================================
void browseform::play_media(QString file,int mode)
{
    if(lookfiletype == MEDIA_PIC)
    {
        if(mode)ui->pic_front_btn->setVisible(true); else ui->pic_front_btn->setVisible(false);
        if(mode)ui->pic_next_btn->setVisible(true); else ui->pic_next_btn->setVisible(false);
        ui->pic_stop_btn->setVisible(false);
        QMatrix matrix;
        ui->progressBar->hide();

        //matrix.rotate(90);
        QImage img(file);
        QImage img1 = img.scaled(PIC_VIEW_WIDTH, PIC_VIEW_HEIGHT);
        label_img->setGeometry((DISPLAY_WIDTH-PIC_VIEW_WIDTH)/2,0,PIC_VIEW_WIDTH, PIC_VIEW_HEIGHT);
        label_img->setPixmap(QPixmap::fromImage(img1));
        ui->label_2->setVisible(false);

    }
    else
    {
        ui->pic_front_btn->setVisible(false);
        ui->pic_next_btn->setVisible(false);
        ui->pic_stop_btn->setVisible(true);
        memset(videoPath, 0, 50);
        memset(h265Path, 0, 50);
        snprintf(videoPath,50,"%s%s",file.toLocal8Bit().data(),".avi");
        snprintf(h265Path,50,"%s%s",file.toLocal8Bit().data(),".h265");
        //memcpy(videoPath, file.toLocal8Bit().data(), file.length());
        //memcpy(h265Path, file.toLocal8Bit().data(), file.length());
        ui->progressBar->show();
        startPlayAvi = 1;//开始播放标志位置于1
        pausePlayAvi = 0;
        ui->pic_stop_btn->setStyleSheet("border-image: url(:/res/dir/stop.png)");
        ui->label_2->setVisible(true);
    }
    back_mode = mode;
    ui->stackedWidget->setCurrentIndex(1);
}

//=================================================================================================================================================
//图片预览
//=================================================================================================================================================
void browseform::play_pic()
{
    if((lookfiletype != MEDIA_PIC)||(cur_index == 1000000))
        return;
    QString imgName = QString(m_save_load.pic_load+list.at(cur_index).fileName());
    if(!imgName.contains(".jpg"))
        return;
    play_media(imgName,1);
}

//=================================================================================================================================================
//视频播放
//=================================================================================================================================================
void browseform::play_video()
{
    if((lookfiletype != MEDIA_VIDEO)||(cur_index == 1000000))
        return;
    QString imgName = QString(m_save_load.avi_load+list.at(cur_index).fileName());
    if(!imgName.contains(".avi"))
        return;
    play_media(QString(m_save_load.avi_load+list.at(cur_index).completeBaseName()),1);
}

//=================================================================================================================================================
//循环播放
//=================================================================================================================================================
void browseform::double_play(QListWidgetItem*Item)
{
    if(cur_index == 1000000)
        return;
    //QString string = Item->text();
    if(lookfiletype == MEDIA_PIC)
    {
        QString imgName = QString(m_save_load.pic_load+list.at(cur_index).fileName());
        play_media(imgName,1);
    }
    else
    {
        play_media(QString(m_save_load.avi_load+list.at(cur_index).completeBaseName()),1);
    }

}

//=================================================================================================================================================
//删除选中的文件, 需要增加确认动作
//=================================================================================================================================================
void browseform::delete_file()
{
    qDebug()<<list.length()<<cur_index;
    int selectRow = cur_index;
    if((list.length() > cur_index)&&cur_index>=0){
        QFile fileTemp(curdir+list.at(cur_index).fileName());
        fileTemp.remove();
        Show_lode_file(curdir);
        if(list.length() > selectRow){
             fileListWidget->item(selectRow)->setSelected(true);
             cur_index = selectRow;
        }

    }
    system("sync");
}

//=================================================================================================================================================
//FICE
//=================================================================================================================================================
void browseform::fileview_back()
{
    this->setcurrentpage(0);
    emit close_form(ficeflag);
}

//=================================================================================================================================================
//图片界面 上一张
//=================================================================================================================================================
void browseform::pic_front()
{
    if(( list.length()>cur_index)&&(cur_index>0))
    {
        cur_index -=1;
        QListWidgetItem *item = fileListWidget->item(cur_index);
        item->setSelected(true);
    }
    play_pic();
}

//=================================================================================================================================================
//图片界面 stop
//=================================================================================================================================================
void browseform::pic_stop()
{
    if(startPlayAvi)
    {
        pausePlayAvi = !pausePlayAvi;
        if(pausePlayAvi)
            ui->pic_stop_btn->setStyleSheet("border-image: url(:/res/dir/play.png)");
        else
            ui->pic_stop_btn->setStyleSheet("border-image: url(:/res/dir/stop.png)");
    }
}

//=================================================================================================================================================
//图片界面 下一张
//=================================================================================================================================================
void browseform::pic_next()
{
    if(( list.length()>1)&&(cur_index<list.length()-1))
    {
        cur_index +=1;
        QListWidgetItem *item = fileListWidget->item(cur_index);
        item->setSelected(true);
    }
    play_pic();
}

//=================================================================================================================================================
//图片界面返回
//=================================================================================================================================================
void browseform::pic_back()
{
    if(back_mode){
    ui->stackedWidget->setCurrentIndex(0);
    this->setcurrentpage(1);
    startPlayAvi = 0;
    pausePlayAvi = 0;
    }
    else{
        ui->stackedWidget->setCurrentIndex(0);
        this->setcurrentpage(1);
        startPlayAvi = 0;
        pausePlayAvi = 0;
        ui->fileview_back_btn->click();
    }
}


//=================================================================================================================================================
//文件管理
//=================================================================================================================================================
void browseform::file_manager()
{
    this->setcurrentpage(2);
    if(save_value==0)
    {
         PutIniKeyInt("Option","Savepath",0,PARAM_FILE);
        localpath_select();
    }
    else if(save_value==2)
    {
         PutIniKeyInt("Option","Savepath",1,PARAM_FILE);
        sdpath_select();
    }
    else if(save_value==2)
    {
         PutIniKeyInt("Option","Savepath",2,PARAM_FILE);
        usbpath_select();
    }
}




//=================================================================================================================================================
//背光设置
//=================================================================================================================================================
void browseform::backlight_set()
{
    this->setcurrentpage(5);
    ui->horizontalSlider->setFocusPolicy(Qt::NoFocus);
    ui->horizontalSlider->setStyleSheet
            ("QSlider::handle:horizontal{width:50px;height:50px;background-color:rgb(77,77,77);margin:-20px 0px -20px 0px;border-radius:25px;}"
            "QSlider::groove:horizontal{height:10px;border:0px; border-radius:5px;background-color:rgb(219,219,219);}"
            "QSlider::add-page:horizontal{background-color:rgb(219,219,219);}"
            "QSlider::sub-page:horizontal{background-color:rgb(70, 70, 70);}");
    ui->horizontalSlider->setValue(backlight_value);
    ui->label_24->setText(tr("%1").arg(backlight_value));
    ui->spinBox->setValue(led_value);
}
1
//=================================================================================================================================================
//切换到"通用设置"页面
//=================================================================================================================================================
void browseform::sleeptime_set()
{
    QString version    = "版本:V1.00";
    QString OV6946MOLD = "当前采集模式：DVP信号";
    QString OH01AMOLD  = "当前采集模式：MIPI信号";

    version.append(QString(VERSION_NUMBER).left(10).right(5));//添加当前版本的日期
    ui->label_9->setText(version);
    ui->function_error->hide();

    //get value
    QSettings settings(PARAM_FILE, QSettings::IniFormat);
    CAMERA_MODLE     = settings.value("Option/camera").toInt();         //1=OV426  0=OH01A
    HDMI_OUT         = settings.value("Option/Size").toInt();
    KEY_AL           = settings.value("key/key_A_long").toInt();
    KEY_AS           = settings.value("key/key_A_short").toInt();
    KEY_BL           = settings.value("key/key_B_long").toInt();
    KEY_BS           = settings.value("key/key_B_short").toInt();
    CAM_CHANGE_EN    = settings.value("Option/Cam_changen").toInt();

    //set value to UI
    ui->chooseBox_A_long->setCurrentIndex(KEY_AL);
    ui->chooseBox_A_short->setCurrentIndex(KEY_AS);
    ui->chooseBox_B_long->setCurrentIndex(KEY_BL);
    ui->chooseBox_B_short->setCurrentIndex(KEY_BS);
    ui->chooseBox_size->setCurrentIndex(HDMI_OUT);
    ui->chooseBox_camera->setCurrentIndex(CAMERA_MODLE);

    //ui->chooseBox_caminput->setCurrentIndex(CAMERA_MODLE);
    //chooseBox_camera	  选择摄像头类型下拉框	   对应参数：CAMERA_MODLE
    //chooseBox_caminput  使能是否可以切换摄像头   对应参数：CAM_CHANGE_EN

    if(CAM_CHANGE_EN == 0)
    {
           ui->chooseBox_camera->setHidden(true);
           ui->label_65->setHidden(true);               //"输入类型"
           if(CAMERA_MODLE == 1)
           {
               ui->label_79->setText(OV6946MOLD);
               ui->label_79->setHidden(false);          //显示"当前采集模式：DVP信号"
           }
           else if(CAMERA_MODLE == 0)
           {
               ui->label_79->setText(OH01AMOLD);
               ui->label_79->setHidden(false);          //显示"当前采集模式：MIPI信号"
           }

    }
   if(CAM_CHANGE_EN == 1)
    {
          ui->chooseBox_camera->setHidden(false);
          ui->label_65->setHidden(false);               //"输入类型"
          ui->label_79->setHidden(true);                //隐藏  :: "当前采集模式：DVP信号"  &&  "当前采集模式：MIPI信号";
          //ui->chooseBox_camera->setCurrentIndex(CAMERA_MODLE);
    }

    this->setcurrentpage(6);
}


//=================================================================================================================================================
//切换到"高级页面"  ui-->adavance_btn
//=================================================================================================================================================
void browseform::adavance_set()
{
    this->setcurrentpage(7);
}

//=================================================================================================================================================
//切换到"图像设置"页面  ui-->help_btn
//=================================================================================================================================================
void browseform::help()
{
    //更新UI界面的值
    ui->rgain_btn->setValue(awb_rgain);
    ui->rgain_label->setText(QString::number(awb_rgain));
    ui->gbgain_btn->setValue(awb_gbgain);
    ui->gbgain_label->setText(QString::number(awb_gbgain));
    ui->grgain_btn->setValue(awb_grgain);
    ui->grgain_label->setText(QString::number(awb_grgain));
    ui->bgain_btn->setValue(awb_bgain);
    ui->bgain_label->setText(QString::number(awb_bgain));

    ui->brightness_btn->setValue(csc_brightness);
    ui->brightness_label->setText(QString::number(csc_brightness));
    ui->constrast_btn->setValue(csc_constrast);
    ui->constrast_label->setText(QString::number(csc_constrast));
    ui->saturastion_btn->setValue(csc_saturation);
    ui->saturastion_label->setText(QString::number(csc_saturation));
    ui->overshoot_btn->setValue(sharp_overshoot);
    ui->overshoot_label->setText(QString::number(sharp_overshoot));

    this->setcurrentpage(10);
}

//=================================================================================================================================================
//返回主界面   ui->set_back_btn
//=================================================================================================================================================
void browseform::set_back()
{
    //ui->widget_6->hide();
    emit close_form(ficeflag);
}


//=================================================================================================================================================
//文件管理  SD-->COPY
//=================================================================================================================================================
void browseform::file_process()
{
    int days = 0,index = 0;
    index = ui->comboBox_Cope->currentIndex();
    switch (days){
        case 0:
            days = 2;
            break;
        case 1:
            days = 7;
            break;
        case 2:
            days = 30;
            break;
        case 3:
            days = 366;
            break;
        default:
            break;
    }
    //SD卡容量足够才开始拷贝
    if(storage_sd>10) copyDirectoryFiles(LOCAL_FILE_PIC_LOAD,SDCARD_FILE_PIC_LOAD,days,false);
    if(storage_sd>10) copyDirectoryFiles(LOCAL_FILE_AVI_LOAD,SDCARD_FILE_AVI_LOAD,days,false);

    //if(storage_udisk>10) copyDirectoryFiles(LOCAL_FILE_PIC_LOAD,UDISK_FILE_PIC_LOAD,days,false);
    //if(storage_udisk>10) copyDirectoryFiles(LOCAL_FILE_AVI_LOAD,UDISK_FILE_AVI_LOAD,days,false);
    ui->copy_btn->setText(QString("拷贝"));
}

//=================================================================================================================================================
//文件管理-->USB COPY
//=================================================================================================================================================
void browseform::file_process_udisk()
{
    int days = 0,index = 0;
    index = ui->comboBox_Copy_Udisk->currentIndex();
    switch (days){
        case 0:
            days = 2;
            break;
        case 1:
            days = 7;
            break;
        case 2:
            days = 30;
            break;
        case 3:
            days = 366;
            break;
        default:
            break;
    }
    //U盘容量足够才开始拷贝
    //if(storage_sd>10) copyDirectoryFiles(LOCAL_FILE_PIC_LOAD,SDCARD_FILE_PIC_LOAD,days,false);
    //if(storage_sd>10) copyDirectoryFiles(LOCAL_FILE_AVI_LOAD,SDCARD_FILE_AVI_LOAD,days,false);
    if(storage_udisk>10) copyDirectoryFiles(LOCAL_FILE_PIC_LOAD,UDISK_FILE_PIC_LOAD,days,false);
    if(storage_udisk>10) copyDirectoryFiles(LOCAL_FILE_AVI_LOAD,UDISK_FILE_AVI_LOAD,days,false);
    ui->copy_btn_Udisk->setText(QString("拷贝"));
}

//=================================================================================================================================================
//复制文件到SD卡
//=================================================================================================================================================
void browseform::copy_file()
{
    ui->copy_btn->setText(QString("拷贝中..."));
    //启动拷贝计时器，QT界面的hide&show在函数执行中不能显示，需要挂靠到外部计时器
    QTimer::singleShot(100,this,SLOT(file_process()));
    //this->setcurrentpage(0);
}

//=================================================================================================================================================
//复制文件到U盘
//=================================================================================================================================================
void browseform::copy_file_USB()
{
    ui->copy_btn_Udisk->setText(QString("拷贝中..."));
    //启动拷贝计时器，QT界面的hide&show在函数执行中不能显示，需要挂靠到外部计时器
    QTimer::singleShot(100,this,SLOT(file_process_udisk()));
    //this->setcurrentpage(0);
}

//=================================================================================================================================================

//=================================================================================================================================================
void browseform::clear_file()
{
    int index = ui->comboBox_Clear->currentIndex();
    QSettings settings(PARAM_FILE, QSettings::IniFormat);
    settings.setValue("Option/dele", index);
    this->setcurrentpage(3);
}

//=================================================================================================================================================

//=================================================================================================================================================
void browseform::filemanager_back()
{
    this->setcurrentpage(0);
}

//=================================================================================================================================================

//=================================================================================================================================================
void browseform::clearfile_confirm()
{
    QSettings settings(PARAM_FILE, QSettings::IniFormat);
    int delet = settings.value("Option/dele").toInt();
    int saveload = settings.value("Option/Savepath").toInt();
    settings.setValue("dele", 1);
    QString pic_load;
    QString avi_load;
    if(!delet){
        pic_load = LOCAL_FILE_PIC_LOAD;
        avi_load = LOCAL_FILE_AVI_LOAD;
    }else{
        pic_load = SDCARD_FILE_PIC_LOAD;
        avi_load = SDCARD_FILE_AVI_LOAD;
    }
    deleteDir(pic_load);
    deleteDir(avi_load);
    system("sync");
    this->setcurrentpage(2);
}

//=================================================================================================================================================
// ae_mold 增加了一个[isp] “ae_mode=0”参数;等于 “1” 手动曝光参数,等于 “0” 为自动曝光参数,“2”为Bypass;
//=================================================================================================================================================
void browseform::Set_AEmold_change(int index)
{
    ae_mode = index;
}

//=================================================================================================================================================

//=================================================================================================================================================
void browseform::clearfile_cancel()
{
    QSettings settings(PARAM_FILE, QSettings::IniFormat);
    settings.setValue("del_true", 0);
    this->setcurrentpage(2);
}





//=================================================================================================================================================
//休眠唤醒
//=================================================================================================================================================
void browseform::sleeptime_back()
{
//    int mainFun = ui->comboBox->currentIndex();
//    QSettings settings(PARAM_FILE, QSettings::IniFormat);
//    settings.setValue("Option/Sleep", mainFun);
    this->setcurrentpage(0);
}


//=================================================================================================================================================
// 修改HDMI输出时图像的显示尺寸
//=================================================================================================================================================
void browseform::change_frame_size(int index){
    hdmi_size = index;
    mppOsdInit();//修改尺寸同理
    //SAMPLE_COMM_VO_StopVO(&stVoConfig);       ?
    //SAMPLE_COMM_VO_StartVO(&stVoConfig);      ?
}


//=================================================================================================================================================
//高级设置-->系统设置---页面的 “保存”
//=================================================================================================================================================
void browseform::frame_setting_save()
{
    QSettings settings(PARAM_FILE, QSettings::IniFormat);
    settings.setValue("option/led_init",init_led);
    settings.setValue("option/led_step",step_led);
    settings.setValue("Option/Cam_changen", CAM_CHANGE_EN);
}

//=================================================================================================================================================
//高级设置-->图像调节---页面的 “保存”
//=================================================================================================================================================
void browseform::image_setting_save()
{
    QSettings settings(PARAM_FILE, QSettings::IniFormat);

    settings.setValue("isp/ae_again",           ae_again);
    settings.setValue("isp/ae_dgain",           ae_dgain);
    settings.setValue("isp/ae_exposure",        ae_exposure);
    settings.setValue("isp/ae_ispdgain",        ae_ispdgain);
    settings.setValue("isp/csc_hue",            csc_hue);
    settings.setValue("isp/ae_mode",            ae_mode);

    //settings.setValue("isp/csc_brightness",     csc_brightness);
    //settings.setValue("isp/csc_constrast",      csc_constrast);
    //settings.setValue("isp/csc_saturation",     csc_saturation);

}
//=================================================================================================================================================
//高级设置-->AWB---页面的 “保存”
//=================================================================================================================================================
void browseform::awbmode_save()
{
    awb_awbmode = ui->chooseBox_awb->currentIndex();
    QSettings settings(PARAM_FILE, QSettings::IniFormat);
    settings.setValue("isp/awb_awbmode",  awb_awbmode);             //白平衡模式
}

//=================================================================================================================================================
//高级设置-->清晰度---页面的 “保存”
//=================================================================================================================================================
void browseform::sharpmode_save()
{
    QSettings settings(PARAM_FILE, QSettings::IniFormat);
    settings.setValue("isp/sharp_texturefreq",  sharp_texturefreq);
    settings.setValue("isp/sharp_edgefreq",     sharp_edgefreq);
    //settings.setValue("isp/sharp_overshoot",   sharp_overshoot);
    settings.setValue("isp/sharp_undershoot",   sharp_undershoot);
    sharp_mode = ui->chooseBox_sharp->currentIndex();
}

//=================================================================================================================================================
void browseform::setCamera_input_en(int index)
{
    CAM_CHANGE_EN = index;
}

//=================================================================================================================================================
//摄像头模式切换
//=================================================================================================================================================
void browseform::change_camera_type(int index)
{
    if(CAM_CHANGE_EN==1)//当高级设置里面允许摄像头的输入模式切换DVP&MIPI时,才可以切换摄像头的输入模式
    {
        /*
        if(index==0)
            system("cp /usr/qt5.12/demos/check_dvp.sh /usr/qt5.12/demos/check.sh");
        if(index==1)
            system("cp /usr/qt5.12/demos/check_mipi.sh /usr/qt5.12/demos/check.sh");

        if(camera_type!=index)
            rec_flag=1;

        camera_type = index;
        QSettings settings(PARAM_FILE, QSettings::IniFormat);
        settings.setValue("option/camera", camera_type);

        //system("reboot");
        */

        CAMERA_MODLE = index;

    }
}

//=================================================================================================================================================
//“通用设置”页面的保存功能函数  连接到pushButton_4
//=================================================================================================================================================
void browseform::chargemode_save()
{
    QSettings settings(PARAM_FILE, QSettings::IniFormat);
    settings.setValue("Option/Size", hdmi_size);
    settings.setValue("Option/Mask", rc_mask_type);

    //保存按键自定义参数
    int as,al,bs,bl;
    as=ui->chooseBox_A_short->currentIndex();
    al=ui->chooseBox_A_long->currentIndex();
    bs=ui->chooseBox_B_short->currentIndex();
    bl=ui->chooseBox_B_long->currentIndex();

    if(as==al||as==bs||as==bl||al==bs||al==bl||bs==bl)
    {
        ui->function_error->show();
    }
    else
    {
        settings.setValue("key/key_A_short",as);
        settings.setValue("key/key_B_short",bs);
        settings.setValue("key/key_A_long" ,al);
        settings.setValue("key/key_B_long" ,bl);
        //ui->back_2->click();
    }

    qDebug()<<"INFO:: chargemode_save-->CAMERA_MODLE::"<<CAMERA_MODLE;    //print  CAMERA_MODLE
    qDebug()<<"INFO:: chargemode_save-->camera_type ::"<<camera_type;     //print save path

    //获取摄像头模式的值
    CAMERA_MODLE = ui->chooseBox_camera->currentIndex();

    if(camera_type!=CAMERA_MODLE)                    //判断摄像头类型是否发生改变
    {
        rec_flag=1;
    }

    camera_type = CAMERA_MODLE;
    settings.setValue("Option/camera", CAMERA_MODLE);

    if(rec_flag)                                     //如果摄像头类型发生改变：则重启系统
    {

        if(CAMERA_MODLE == 1 )
            system("cp /usr/qt5.12/demos/check_dvp.sh /usr/qt5.12/demos/check.sh");
        if(CAMERA_MODLE == 0 )
            system("cp /usr/qt5.12/demos/check_mipi.sh /usr/qt5.12/demos/check.sh");

        rec_flag=0;
        system("reboot");
    }
}

//=================================================================================================================================================
//图像设置界面-->“保存设置”
//=================================================================================================================================================
void browseform::on_colorsetsave_btn_clicked()
{
    //获取滑动调的值
    int mask_rgain  = ui->rgain_btn->value();
    int mask_gbgain = ui->gbgain_btn->value();
    int mask_grgain = ui->grgain_btn->value();
    int mask_bgain  = ui->bgain_btn->value();

    //将滑动条的mask值转化为真是的值
    awb_rgain       = mask_rgain;                 //mask_rgain*5;
    awb_gbgain      = mask_gbgain;                //mask_gbgain*5;
    awb_grgain      = mask_grgain;                //mask_grgain*5;
    awb_bgain       = mask_bgain;                 //mask_bgain*5;

    //获取滑动调的值
    csc_brightness  = ui->brightness_btn->value();
    csc_constrast   = ui->constrast_btn->value();
    //csc_hue         = ui->hue_btn->value();
    csc_saturation  = ui->saturastion_btn->value();
    sharp_overshoot = ui->overshoot_btn->value();
    sharp_undershoot =sharp_overshoot + 10 ;

    //将图像参数写入配置文件
    QSettings settings(PARAM_FILE, QSettings::IniFormat);
    settings.setValue("isp/csc_brightness",     csc_brightness      );
    settings.setValue("isp/csc_constrast",      csc_constrast       );
    //settings.setValue("isp/csc_hue",            csc_hue           );
    settings.setValue("isp/csc_saturation",     csc_saturation      );
    settings.setValue("isp/awb_rgain",          awb_rgain           );
    settings.setValue("isp/awb_grgain",         awb_grgain          );
    settings.setValue("isp/awb_gbgain",         awb_gbgain          );
    settings.setValue("isp/awb_bgain",          awb_bgain           );
    settings.setValue("isp/sharp_overshoot",    sharp_overshoot     );
    settings.setValue("isp/sharp_overshoot",    sharp_undershoot    );
}

//=================================================================================================================================================
//图像设置界面-->“恢复默认”
//=================================================================================================================================================
void browseform::on_colorsetdefaut_btn_clicked()
{
    int def_awb_rgain ;                 //白平衡rgain默认值
    int def_awb_grgain;                 //白平衡grgain默认值
    int def_awb_gbgain;                 //白平衡gbgain默认值
    int def_awb_bgain ;                 //白平衡bgain默认值

    if(CAMERA_MODLE == 1)        //DVP camera OV6946
    {
        def_awb_rgain   = 280;           //白平衡rgain默认值
        def_awb_grgain  = 260;           //白平衡grgain默认值
        def_awb_gbgain  = 260;           //白平衡gbgain默认值
        def_awb_bgain   = 350;           //白平衡bgain默认值
    }
    if(CAMERA_MODLE == 0)        //mipi camera OS01A10
    {
        def_awb_rgain   = 300;           //白平衡rgain默认值
        def_awb_grgain  = 280;           //白平衡grgain默认值
        def_awb_gbgain  = 280;           //白平衡gbgain默认值
        def_awb_bgain   = 420;           //白平衡bgain默认值
    }
    csc_brightness      = 55;           //亮度默认值
    csc_constrast       = 60;           //对比度默认值
    csc_saturation      = 50;           //饱和度默认值
    csc_saturation      = 50;           //饱和度默认值

    sharp_overshoot     = 15;           //
    sharp_undershoot    = 25;           //
    //获取滑动调的值
    awb_rgain  = def_awb_rgain;
    awb_grgain = def_awb_grgain;
    awb_gbgain = def_awb_gbgain;
    awb_bgain  = def_awb_bgain;

    //更新UI界面的值
    ui->rgain_btn->setValue(def_awb_rgain);
    ui->rgain_label->setText(QString::number(def_awb_rgain));
    ui->gbgain_btn->setValue(def_awb_gbgain);
    ui->gbgain_label->setText(QString::number(def_awb_gbgain));
    ui->grgain_btn->setValue(def_awb_grgain);
    ui->grgain_label->setText(QString::number(def_awb_grgain));
    ui->bgain_btn->setValue(def_awb_bgain);
    ui->bgain_label->setText(QString::number(def_awb_bgain));

    ui->brightness_btn->setValue(csc_brightness);
    ui->brightness_label->setText(QString::number(csc_brightness));
    ui->constrast_btn->setValue(csc_constrast);
    ui->constrast_label->setText(QString::number(csc_constrast));
    ui->saturastion_btn->setValue(csc_saturation);
    ui->saturastion_label->setText(QString::number(csc_saturation));
    ui->overshoot_btn->setValue(sharp_overshoot);
    ui->overshoot_label->setText(QString::number(sharp_overshoot));

    //将图像参数写入配置文件
    QSettings settings(PARAM_FILE, QSettings::IniFormat);
    settings.setValue("isp/csc_brightness",     csc_brightness  );
    settings.setValue("isp/csc_constrast",      csc_constrast   );
    settings.setValue("isp/csc_saturation",     csc_saturation  );
    settings.setValue("isp/awb_rgain",          awb_rgain       );
    settings.setValue("isp/awb_grgain",         awb_grgain      );
    settings.setValue("isp/awb_gbgain",         awb_gbgain      );
    settings.setValue("isp/awb_bgain",          awb_bgain       );
    settings.setValue("isp/sharp_overshoot",    sharp_overshoot );
    settings.setValue("isp/sharp_undershoot",   sharp_undershoot);
}


//=================================================================================================================================================
//改变曝光模式
//=================================================================================================================================================
void browseform::Set_AEmold_changed()
{
    ae_mode = ui->chooseBox_aemold->currentIndex();
    QSettings settings(PARAM_FILE, QSettings::IniFormat);
    settings.setValue("isp/ae_mold", ae_mode);

    mppIsp_AUTO_EXPOSURE(0,ae_mode);
}

//=================================================================================================================================================
//LDCI_mode模式
//=================================================================================================================================================
void browseform::LDCImode_change(int index)
{
    LDCI_mode =  ui->chooseBox_LDCImode->currentIndex();
    QSettings settings(PARAM_FILE, QSettings::IniFormat);
    settings.setValue("isp/LDCI_mode", LDCI_mode);

}

//=================================================================================================================================================
//LDCI_enable
//=================================================================================================================================================
void browseform::LDCIen_change(int index)
{
    LDCI_en = ui->chooseBox_LDCIen->currentIndex();


    QSettings settings(PARAM_FILE, QSettings::IniFormat);
    settings.setValue("isp/LDCI_enable", LDCI_en);

}

//=================================================================================================================================================
//开启、关闭图像去雾
//=================================================================================================================================================
void browseform::dehaze_change()
{
    DE_enable =ui->chooseBox_dehaze->currentIndex();
    ISP_DEHAZE_ATTR_S pstDehazeAttr;
    HI_MPI_ISP_GetDehazeAttr(0, &pstDehazeAttr);
    if(DE_enable)
        pstDehazeAttr.bEnable = HI_TRUE;
    else
        pstDehazeAttr.bEnable = HI_FALSE;

    HI_MPI_ISP_SetDehazeAttr(0, &pstDehazeAttr);

    QSettings settings(PARAM_FILE, QSettings::IniFormat);
    settings.setValue("isp/DE_enable", DE_enable);
}

//=================================================================================================================================================
//开启、关闭噪声碎化
//=================================================================================================================================================
void browseform::denoise_change( )
{
    DE_model =ui->chooseBox_denoise->currentIndex();
    switch (DE_model)
    {
    case 0:
        printf("0");
        mppIspDeCtrl(0,DE_enable,DE_model,DE_GlobaGain,DE_GainLF,DE_GainHF) ;
        break;
    case 1:
        printf("1");
        mppIspDeCtrl(0,DE_enable,DE_model,DE_GlobaGain,DE_GainLF,DE_GainHF) ;
        break;
    default:
        break;
    }

    QSettings settings(PARAM_FILE, QSettings::IniFormat);
    settings.setValue("isp/DE_enable", DE_model);
}

//=================================================================================================================================================
//开启、关闭局部增强
//=================================================================================================================================================
void browseform::LDCI_enable( )
{
    LDCI_en =ui->chooseBox_LDCIen->currentIndex();
    switch (LDCI_en)
    {
    case 0:
        printf("0");
        mppIspLdciCtrl(0,LDCI_en,LDCI_mode,LDCI_LPFSigma, LDCI_Blc, LDCI_posmean,LDCI_possigma,LDCI_poswgt, LDCI_negmean,LDCI_negsigma,LDCI_negwgt);
        break;
    case 1:
        printf("1");
        mppIspLdciCtrl(0,LDCI_en,LDCI_mode,LDCI_LPFSigma, LDCI_Blc, LDCI_posmean,LDCI_possigma,LDCI_poswgt, LDCI_negmean,LDCI_negsigma,LDCI_negwgt);
        break;
    default:
        break;
    }

    QSettings settings(PARAM_FILE, QSettings::IniFormat);
    settings.setValue("isp/LDCI_mode", LDCI_en);
}

//=================================================================================================================================================
//局部增强模式选择
//=================================================================================================================================================
void browseform::LDCI_mode_change( )
{
    LDCI_en   =ui->chooseBox_LDCIen->currentIndex();
    LDCI_mode =ui->chooseBox_LDCImode->currentIndex();

    if(LDCI_en)
    {
       mppIspLdciCtrl(0,LDCI_en,LDCI_mode,LDCI_LPFSigma, LDCI_Blc, LDCI_posmean,LDCI_possigma,LDCI_poswgt, LDCI_negmean,LDCI_negsigma,LDCI_negwgt);
    }

}


//=================================================================================================================================================
//主题设置
//=================================================================================================================================================
void browseform::theme_save()
{
    int mainFun = ui->chooseBox_3->currentIndex();          //主题设置
    QSettings settings(PARAM_FILE, QSettings::IniFormat);   //
    settings.setValue("Option/Style", mainFun);             //
}

//=================================================================================================================================================
//曝光时间调节
//=================================================================================================================================================
void browseform::exposure_changed(int value)
{
    if(ae_mode)
    {
        ae_exposure = value;
        ui->exposure_btn->setValue(value);
        ui->exposure_label->setText(QString::number(value));
    }
}

//=================================================================================================================================================
//模拟增益调节
//=================================================================================================================================================
void browseform::again_changed(int value)
{
    if(ae_mode)
    {
        ae_again = value;
        ui->again_btn->setValue(value);
        ui->again_label->setText(QString::number(value));
    }
}

//=================================================================================================================================================
//数字增益调节
//=================================================================================================================================================
void browseform::dgain_changed(int value)
{
    if(ae_mode)
    {
        ae_dgain = value;
        ui->dgain_btn->setValue(value);
        ui->dgain_label->setText(QString::number(value));
    }
}

//=================================================================================================================================================
//ISP增益调节
//=================================================================================================================================================
void browseform::ispgain_changed(int value)
{
    if(ae_mode)
    {
        ae_ispdgain = value;
        ui->ispgain_btn->setValue(value);
        ui->ispgain_label->setText(QString::number(value));
    }
}

//=================================================================================================================================================
//亮度调节
//=================================================================================================================================================
void browseform::brightness_changed(int value)
{
    csc_brightness = value;
    ui->brightness_btn->setValue(value);
    ui->brightness_label->setText(QString::number(value));
}

//=================================================================================================================================================
//对比度调节
//=================================================================================================================================================
void browseform::constrast_changed(int value)
{
    csc_constrast = value;
    ui->constrast_btn->setValue(value);
    ui->constrast_label->setText(QString::number(value));
}

//=================================================================================================================================================
//色调调节Hue
//=================================================================================================================================================
void browseform::hue_changed(int value)
{
    csc_hue = value;
    ui->hue_btn->setValue(value);
    ui->hue_label->setText(QString::number(value));
}

//=================================================================================================================================================
//饱和度调节
//=================================================================================================================================================
void browseform::saturastion_changed(int value)
{
    csc_saturation = value;
    ui->saturastion_btn->setValue(value);
    ui->saturastion_label->setText(QString::number(value));
}

//=================================================================================================================================================
//关闭FICE，未使用
//=================================================================================================================================================
void browseform::fice_close()
{
    ficeflag = 0;
    ui->local_btn_2->setStyleSheet("border-image:url(:/res/set/radio.png)");
    ui->sd_btn_2->setStyleSheet("border-image:url(:/res/set/unradio.png)");

    QSettings settings(PARAM_FILE, QSettings::IniFormat);
    settings.setValue("Option/fice", ficeflag);
}

//=================================================================================================================================================
//开启FICE,未使用
//=================================================================================================================================================
void browseform::fice_open()
{
    ficeflag = 1;
    ui->sd_btn_2->setStyleSheet("border-image:url(:/res/set/radio.png)");
    ui->local_btn_2->setStyleSheet("border-image:url(:/res/set/unradio.png)");

    QSettings settings(PARAM_FILE, QSettings::IniFormat);
    settings.setValue("Option/fice", ficeflag);
}



//=================================================================================================================================================
//设置色温
//=================================================================================================================================================
void browseform::temperature_change(int value)
{
    if(awb_awbmode == 1)
    {
        awb_temperature = value;
        ui->temperature_btn->setValue(value);
        ui->temperature_label->setText(QString::number(value));
    }
}

//=================================================================================================================================================
//设置 rgain_btn
//=================================================================================================================================================
void browseform::rgain_change(int value)
{
    if(awb_awbmode == 2)
    {
        //awb_rgain = value;
        ui->rgain_btn->setValue(value);
        ui->rgain_label->setText(QString::number(value));
    }
}

//=================================================================================================================================================
//设置 grain_btn
//=================================================================================================================================================
void browseform::grgain_change(int value)
{
    if(awb_awbmode == 2)
    {
        //awb_grgain = value;
        ui->grgain_btn->setValue(value);
        ui->grgain_label->setText(QString::number(value));
    }
}

//=================================================================================================================================================
//设置 gbgain_btn
//=================================================================================================================================================
void browseform::gbgain_change(int value)
{
    if(awb_awbmode == 2)
    {
        //awb_gbgain = value;
        ui->gbgain_btn->setValue(value);
        ui->gbgain_label->setText(QString::number(value));
    }
}

//=================================================================================================================================================
//设置 bgain_btn
//=================================================================================================================================================
void browseform::bgain_change(int value)
{
    if(awb_awbmode == 2)
    {
        //awb_bgain = value;
        ui->bgain_btn->setValue(value);
        ui->bgain_label->setText(QString::number(value));
    }
}

//=================================================================================================================================================
//Sensor采样模式选择函数
//=================================================================================================================================================
void browseform::CB_sample_Changed(int index)
{
    switch (index)          //可以考虑字符串拼接的方式简化代码
    {
    case 0:
        printf("0");
        system("cp /usr/qt5.12/demos/sensor_rst_0.sh /usr/qt5.12/demos/sensor_rst.sh -f");
        system("sh /usr/qt5.12/demos/sensor_rst.sh >/dev/null");
        break;
    case 1:
        printf("1");
        system("cp /usr/qt5.12/demos/sensor_rst_1.sh /usr/qt5.12/demos/sensor_rst.sh -f");
        system("sh /usr/qt5.12/demos/sensor_rst.sh >/dev/null");
        break;
    case 2:
        printf("2");
        system("cp /usr/qt5.12/demos/sensor_rst_2.sh /usr/qt5.12/demos/sensor_rst.sh -f");
        system("sh /usr/qt5.12/demos/sensor_rst.sh >/dev/null");
        break;
    case 3:
        printf("3");
        system("cp /usr/qt5.12/demos/sensor_rst_3.sh /usr/qt5.12/demos/sensor_rst.sh -f");
        system("sh /usr/qt5.12/demos/sensor_rst.sh >/dev/null");
        break;
    default:
        break;
    }

    sample = index;
    QSettings settings(PARAM_FILE, QSettings::IniFormat);
    settings.setValue("Option/sample", index);
}

//=================================================================================================================================================
//细节增强,手动模式下才能调节
//=================================================================================================================================================
void browseform::texturefreq_change(int value)
{
    if(sharp_mode == 1)
    {
        sharp_texturefreq = value;
        ui->texturefreq_btn->setValue(value);
        ui->texturefreq_label->setText(QString::number(value));     //设置滑动调后面的数字的值
    }
}

//=================================================================================================================================================
//边沿增强,手动模式下才能调节
//=================================================================================================================================================
void browseform::edgefreq_change(int value)
{
    if(sharp_mode == 1)
    {
        sharp_edgefreq = value;
        ui->edgefreq_btn->setValue(value);
        ui->edgefreq_label->setText(QString::number(value));        //设置滑动调后面的数字的值
    }
}

//=================================================================================================================================================
//白点增强,手动模式下才能调节
//=================================================================================================================================================
void browseform::overshoot_change(int value)
{
    if(sharp_mode == 1)
    {
        sharp_overshoot = value;
        ui->overshoot_btn->setValue(value);
        ui->overshoot_label->setText(QString::number(value));//设置滑动调后面的数字的值
    }
}

//=================================================================================================================================================
//黑点增强,手动模式下才能调节
//=================================================================================================================================================
void browseform::undershoot_change(int value)
{
    if(sharp_mode == 1)
    {
        sharp_undershoot = value;
        ui->undershoot_btn->setValue(value);
        ui->undershoot_label->setText(QString::number(value));//设置滑动调后面的数字的值
    }
}

//=================================================================================================================================================
//set LDCI_LPFSigma_change
//=================================================================================================================================================
void browseform::LDCI_LPFSigma_change(int value)
{
    LDCI_LPFSigma = value;
    ui->LDCI_LPFSigma->setValue(value);
    ui->LDCI_LPFSigma_label_2->setText(QString::number(value));
}

//=================================================================================================================================================
//set LDCI_Blc_change
//=================================================================================================================================================
void browseform::LDCI_Blc_change(int value)
{
    LDCI_Blc = value;
    ui->LDCI_Blc->setValue(value);
    ui->LDCI_Blc_label_2->setText(QString::number(value));
}

//=================================================================================================================================================
//set LDCI_posmean_change
//=================================================================================================================================================
void browseform::LDCI_posmean_change(int value)
{
    LDCI_posmean = value;
    ui->LDCI_posmean->setValue(value);
    ui->LDCI_posmean_label_2->setText(QString::number(value));
}

//=================================================================================================================================================
//set LDCI_possigma_change
//=================================================================================================================================================
void browseform::LDCI_possigma_change(int value)
{
    LDCI_possigma = value;
    ui->LDCI_possigma->setValue(value);
    ui->LDCI_possigma_label_2->setText(QString::number(value));
}

//=================================================================================================================================================
//set LDCI_poswgt_change
//=================================================================================================================================================
void browseform::LDCI_poswgt_change(int value)
{
    LDCI_poswgt = value;
    ui->LDCI_poswgt->setValue(value);
    ui->LDCI_poswgt_label_2->setText(QString::number(value));
}

//=================================================================================================================================================
//set LDCI_negmean_change
//=================================================================================================================================================
void browseform::LDCI_negmean_change(int value)
{
    LDCI_negmean = value;
    ui->LDCI_negmean->setValue(value);
    ui->LDCI_negmean_label_2->setText(QString::number(value));
}

//=================================================================================================================================================
//set LDCI_negsigma_change
//=================================================================================================================================================
void browseform::LDCI_negsigma_change(int value)
{
    LDCI_negsigma = value;
    ui->LDCI_negsigma->setValue(value);
    ui->LDCI_negsigma_label_2->setText(QString::number(value));
}

//=================================================================================================================================================
//set LDCI_negwgt_change
//=================================================================================================================================================
void browseform::LDCI_negwgt_change(int value)
{
    LDCI_negwgt = value;
    ui->LDCI_negwgt->setValue(value);
    ui->LDCI_negwgt_label_2->setText(QString::number(value));
}

//=================================================================================================================================================
//注意: LED灯输出电流=(LED灯亮度初始值+LED档位x调节幅值)x3mA
//LED亮度初始值
//=================================================================================================================================================
void browseform::on_chooseBox_size_2_currentIndexChanged(int index)
{
    init_led = index;
}

//=================================================================================================================================================
//LED调节幅值
//=================================================================================================================================================
void browseform::on_chooseBox_mask_2_currentIndexChanged(int index)
{
    step_led = index;
}

//=================================================================================================================================================
//开启去雾 dehaze
//=================================================================================================================================================
void browseform::on_pushButton_2_clicked()
{
}

//=================================================================================================================================================
//关闭去雾 dehaze
//=================================================================================================================================================
void browseform::on_pushButton_3_clicked()
{
}


//=================================================================================================================================================
//去雾参数 滑动条
//=================================================================================================================================================
void browseform::on_horizontalSlider_2_valueChanged(int value)
{

    ISP_DEHAZE_ATTR_S pstDehazeAttr;
    HI_MPI_ISP_GetDehazeAttr(0, &pstDehazeAttr);
    pstDehazeAttr.bEnable = HI_TRUE;
    pstDehazeAttr.u16TmprfltIncrCoef = value;
    HI_MPI_ISP_SetDehazeAttr(0, &pstDehazeAttr);


    QString string = "dehaze_v+:"+QString::number(value);
    ui->label_73->setText(string);
}

//=================================================================================================================================================
//去雾参数 滑动条
//=================================================================================================================================================
void browseform::on_horizontalSlider_3_valueChanged(int value)
{

    ISP_DEHAZE_ATTR_S pstDehazeAttr;
        HI_MPI_ISP_GetDehazeAttr(0, &pstDehazeAttr);
        pstDehazeAttr.bEnable = HI_TRUE;
        pstDehazeAttr.u16TmprfltDecrCoef = value;
        HI_MPI_ISP_SetDehazeAttr(0, &pstDehazeAttr);

        QString string = "dehaze_v-:"+QString::number(value);
        ui->label_74->setText(string);
}

//=================================================================================================================================================
//HDMI切换成1080P
//=================================================================================================================================================
void browseform::on_ButonHDMI_1080P_clicked()
{
    hdmi_disp_mode = HDMI_1080P;
    mppOsdInit();//修改遮罩以后要初始化显示一下，才能正常显示遮罩
}

//=================================================================================================================================================
//HDMI切换成720P
//=================================================================================================================================================
void browseform::on_ButonHDMI_720P_clicked()
{
    hdmi_disp_mode = HDMI_720P;
    mppOsdInit();//修改遮罩以后要初始化显示一下，才能正常显示遮罩
}


//=================================================================================================================================================
//密码默认6位数，可以设置其他任意长度
//=================================================================================================================================================
void browseform::on_save_code_clicked(){
    if(code.length()==6){
        int passwd = code.toInt();
        QSettings settings("/etc/watermask/passwd.ini", QSettings::IniFormat);
        settings.beginGroup("Code");
        settings.setValue("passwd", passwd);
        ui->label_28->setText("密码保存成功");
        code="";
    }else{
        ui->label_28->setText("请输入6位数");
        code="";
    }
}

//=================================================================================================================================================
//初始密码参数
//=================================================================================================================================================
void browseform::on_default_code_clicked(){
    int passwd = 180921;
    QSettings settings("/etc/watermask/passwd.ini", QSettings::IniFormat);
    settings.beginGroup("Code");
    settings.setValue("passwd", passwd);
    ui->label_28->setText("已恢复默认");
    code="";
}

//=================================================================================================================================================
//密码输入退格
//=================================================================================================================================================
void browseform::on_delete_code_clicked(){
    code.chop(1);
    ui->lineEdit_2->setText(code);
}

//=================================================================================================================================================
// 返回主界面
//=================================================================================================================================================
void browseform::advanced_back()
{
    this->setcurrentpage(0);
}

//=================================================================================================================================================
// Beep test OFF
//=================================================================================================================================================
void browseform::pushButton_beep_off()
{
    system("echo 0 > /sys/class/gpio/gpio43/value");
    system("echo 43 > /sys/class/gpio/unexport");
}
//=================================================================================================================================================
//Beep test ON
//=================================================================================================================================================
void browseform::pushButton_beep_on()
{
    system("echo 43 > /sys/class/gpio/export");
    system("echo out > /sys/class/gpio/gpio43/direction");
    system("echo 1 > /sys/class/gpio/gpio43/value");
}


//=================================================================================================================================================
//密码输入错误后，跳转到“页面0”
//=================================================================================================================================================
void browseform::passwd_error()
{
    this->setcurrentpage(0);
}

//=================================================================================================================================================
//色彩设置的返回按键，点击后跳转到“页面0”
//=================================================================================================================================================
void browseform::help_back()
{
    this->setcurrentpage(0);
}


QFileInfoList list;
int list_num=0;
int Mask_mode;           //图像切角模式
int Save_mode;           //保存路径参数
int Size_mode;           //图像尺寸模式

extern int noFreeRoom_flag;


char r_value[10],g_value[10];
void * mainwindow_run(void *pArgs)
{
    static int i = 0;
    QIcon icon1;
    #if 0
    standby_init();
    connect(m_browseform,  SIGNAL(close_form(int)), this,   SLOT(ShowVideo(int)));          //连接菜单栏的返回主界面事件
    #endif
    //PutIniKeyInt("isp","awb_bgain",stAWBCalibGain.u16AvgBgain,PARAM_FILE);
    //GetIniKeyInt(char *title,char *key,char *filename);
    while(1)
    {
        if(vhandle)   //设置录像图标大小变化, 已经修改成蓝白色logo 0.5s切换显示
        {
            if(i % 2 == 1)
            {
                icon1.addFile(QStringLiteral(":/res/10inch/record1_b.png"), QSize(), QIcon::Normal, QIcon::Off);
                ui->Btn_Video->setIcon(icon1);
            }
            else
            {
                icon1.addFile(QStringLiteral(":/res/10inch/record1_w.png"), QSize(), QIcon::Normal, QIcon::Off);
                ui->Btn_Video->setIcon(icon1);
                //ui->Btn_Video->setIconSize(QSize(105, 105));  设置图标尺寸为105*105     BY EDWIN
            }
            i=!i;
        }

        QSettings settings(PARAM_FILE,QSettings::IniFormat);                    //打开配置文件
        QString led_level = settings.value("Option/Led").toString();            //读取LED的照明等级

        Size_mode         = settings.value("Option/Size").toInt();              //图像尺寸
        Save_mode         = settings.value("Option/Savepath").toInt();          //图片和视频保存路径的参数
        Mask_mode         = settings.value("Option/Mask").toInt();              //图像

        QDate date = date.currentDate();
        QString date_sting = "DATE : " + date.toString("yyyy-MM-dd");           //标签上日期显示
        ui->osddate_label->setText(date_sting);
        ui->osddate_label->show();

        QDateTime time = QDateTime::currentDateTime();
        QString time_sting = "TIME : " + time.toString("hh:mm:ss");             //标签上时间显示
        ui->osdtime_label->setText(time_sting);
        ui->osdtime_label->show();

        QString size_sting;
        if(Size_mode == 0)
            size_sting = "IMAGE : 600x600" ;                                    //set imageSize600x600
        else if(Size_mode == 1)
            size_sting = "IMAGE : 800x800" ;                                    //set imageSize800x800
        else if(Size_mode == 2)
            size_sting = "IMAGE : 1080x1080" ;                                  //set imageSize1080x1080
        ui->imagesize_label->setText(size_sting);
        ui->imagesize_label->show();

        QString hdmi_sting = "HDMI : 1080P@60" ;                                //set HDMI Display 1080P@60
        ui->hdmi_label->setText(hdmi_sting);
        ui->hdmi_label->show();

        QString light_sting = "LIGHT : LEVEL_"+ led_level ;                     //标签显示照明等级
        ui->light_label->setText(light_sting);
        ui->light_label->show();

        QString save_path;
        if(Save_mode == 0)
            save_path = "SAVE  : System" ;                                      //保存路径:EMMC
        else if(Save_mode == 1)
            save_path = "SAVE  : SD-Card" ;                                     //保存路径:SD-Card
        else if(Save_mode == 2)
            save_path = "SAVE  : U-Disk" ;                                      //保存路径:U-Disk
        ui->savepath_label->setText(save_path);
        ui->savepath_label->show();
        usleep(500000);
    }

}


//======================================================================================================================
//"浏览图标"处理函数
void on_Btn_Ranse_clicked()
{
    if(vhandle){
        return;
    }
    camera_showpicfSet_status(false);
    m_browseform->setcurrentpage(1);
    ui->stackedWidget->setCurrentIndex(1);
}

//======================================================================================================================
//"设置图标"处理函数
void on_Btn_bower_clicked()
{
    if(vhandle){
        return;
    }
    camera_showpicfSet_status(false);
    m_browseform->setcurrentpage(0);
    ui->stackedWidget->setCurrentIndex(1);
}

//======================================================================================================================
//显示左边栏的三张预览图的其中之一

void MainWindow::play_number_pic(int num)
{
    switch (num)
    {
    case 1:
        if(list_num>=1)
        {
            if(vhandle)
            {
                return;
            }
            camera_showpicfSet_status(false);
            m_browseform->setcurrentpage(1);
            m_browseform->lookfiletype = 0;
            m_browseform->play_media(list.at(list.count()-1).absoluteFilePath(),0);
            ui->stackedWidget->setCurrentIndex(1);
            printf("1\n");
            break;
        }
    case 2:
        if(list_num>=2)
        {
            if(vhandle)
            {
                return;
            }
            camera_showpicfSet_status(false);
            m_browseform->setcurrentpage(1);
            m_browseform->lookfiletype = 0;
            m_browseform->play_media(list.at(list.count()-2).absoluteFilePath(),0);
            ui->stackedWidget->setCurrentIndex(1);
        }
        printf("2\n");
        break;
    case 3:
        if(list_num>=3)
        {
            if(vhandle)
            {
                return;
            }
            camera_showpicfSet_status(false);
            m_browseform->setcurrentpage(1);
            m_browseform->lookfiletype = 0;
            m_browseform->play_media(list.at(list.count()-3).absoluteFilePath(),0);
            ui->stackedWidget->setCurrentIndex(1);
        }
        printf("3\n");
        break;
    default:
        break;
    }

}


//======================================================================================================================
//======================================================================================================================
//显示图像标定的画面，现已不用
//======================================================================================================================
//======================================================================================================================
void ShowVideo(int fice)
{
    fice = 0;
    camer->full = !fice;
    camera_showpicfSet_status(true);
    if(fice)
    {
        ui->stackedWidget->setCurrentIndex(2);      //显示图像标定的画面，现已不用
        ui->setting->setCurrentIndex(0);
    }
    else
        ui->stackedWidget->setCurrentIndex(0);
        //ui->stackedWidget_tool->hide();
}

//======================================================================================================================
//以下是图像标定相关，目前已经没有用到
void MainWindow::on_next1_5_clicked()
{
    ui->stackedWidget->setCurrentIndex(2);      //显示图像标定的画面，现已不用


    ui->again_btn->setValue(m_browseform->ae_again);
    ui->again_label->setText(QString::number(m_browseform->ae_again));
    ui->dgain_btn->setValue(m_browseform->ae_dgain);
    ui->dgain_label->setText(QString::number(m_browseform->ae_dgain));
    ui->exposure_btn->setValue(m_browseform->ae_exposure);
    ui->exposure_label->setText(QString::number(m_browseform->ae_exposure));
    ui->ispgain_btn->setValue(m_browseform->ae_ispdgain);
    ui->ispgain_label->setText(QString::number(m_browseform->ae_ispdgain));
    ui->brightness_btn->setValue(m_browseform->csc_brightness);
    ui->brightness_label->setText(QString::number(m_browseform->csc_brightness));
    ui->constrast_btn->setValue(m_browseform->csc_constrast);
    ui->constrast_label->setText(QString::number(m_browseform->csc_constrast));
    ui->hue_btn->setValue(m_browseform->csc_hue);
    ui->hue_label->setText(QString::number(m_browseform->csc_hue));
    ui->saturastion_btn->setValue(m_browseform->csc_saturation);
    ui->saturastion_label->setText(QString::number(m_browseform->csc_saturation));

    ui->rgain_btn->setValue(m_browseform->awb_rgain);
    ui->rgain_label->setText(QString::number(m_browseform->awb_rgain));
    ui->grgain_btn->setValue(m_browseform->awb_grgain);
    ui->grgain_label->setText(QString::number(m_browseform->awb_grgain));
    ui->gbgain_btn->setValue(m_browseform->awb_gbgain);
    ui->gbgain_label->setText(QString::number(m_browseform->awb_gbgain));
    ui->bgain_btn->setValue(m_browseform->awb_bgain);
    ui->bgain_label->setText(QString::number(m_browseform->awb_bgain));
    if(m_browseform->awb_awbmode == 0)
    {
        ui->sd_btn_3->setStyleSheet("border-image:url(:/res/set/unradio.png)");
        ui->local_btn_3->setStyleSheet("border-image:url(:/res/set/radio.png)");
    }
    if(m_browseform->awb_awbmode == 2)
    {
        ui->sd_btn_3->setStyleSheet("border-image:url(:/res/set/radio.png)");
        ui->local_btn_3->setStyleSheet("border-image:url(:/res/set/unradio.png)");
    }
    ui->texturefreq_btn->setValue(m_browseform->sharp_texturefreq);
    ui->texturefreq_label->setText(QString::number(m_browseform->sharp_texturefreq));
    ui->edgefreq_btn->setValue(m_browseform->sharp_edgefreq);
    ui->edgefreq_label->setText(QString::number(m_browseform->sharp_edgefreq));
    ui->overshoot_btn->setValue(m_browseform->sharp_overshoot);
    ui->overshoot_label->setText(QString::number(m_browseform->sharp_overshoot));
    ui->undershoot_btn->setValue(m_browseform->sharp_undershoot);
    ui->undershoot_label->setText(QString::number(m_browseform->sharp_undershoot));
    if(m_browseform->sharp_mode == 0)
    {
        ui->sd_btn_4->setStyleSheet("border-image:url(:/res/set/unradio.png)");
        ui->local_btn_4->setStyleSheet("border-image:url(:/res/set/radio.png)");
    }
    if(m_browseform->sharp_mode == 1)
    {
        ui->sd_btn_4->setStyleSheet("border-image:url(:/res/set/radio.png)");
        ui->local_btn_4->setStyleSheet("border-image:url(:/res/set/unradio.png)");
    }
    ui->ccmr_btn->setValue(m_browseform->ccm_rr);
    ui->ccmr_label->setText(QString::number(m_browseform->ccm_rr));
    ui->ccmg_btn->setValue(m_browseform->ccm_rg);
    ui->ccmg_label->setText(QString::number(m_browseform->ccm_rg));
    ui->ccmb_btn->setValue(m_browseform->ccm_rb);
    ui->ccmb_label->setText(QString::number(m_browseform->ccm_rb));
    ui->ccmr_btn_2->setValue(m_browseform->ccm_gr);
    ui->ccmr_label_2->setText(QString::number(m_browseform->ccm_gr));
    ui->ccmg_btn_2->setValue(m_browseform->ccm_gg);
    ui->ccmg_label_2->setText(QString::number(m_browseform->ccm_gg));
    ui->ccmb_btn_2->setValue(m_browseform->ccm_gb);
    ui->ccmb_label_2->setText(QString::number(m_browseform->ccm_gb));
    ui->ccmr_btn_3->setValue(m_browseform->ccm_br);
    ui->ccmr_label_3->setText(QString::number(m_browseform->ccm_br));
    ui->ccmg_btn_3->setValue(m_browseform->ccm_bg);
    ui->ccmg_label_3->setText(QString::number(m_browseform->ccm_bg));
    ui->ccmb_btn_3->setValue(m_browseform->ccm_bb);
    ui->ccmb_label_3->setText(QString::number(m_browseform->ccm_bb));
    ui->setting->setCurrentIndex(1);
}

//======================================================================================================================
//
void MainWindow::on_save1_5_clicked()
{
    camera_showpicfSet_status(false);
    m_browseform->setcurrentpage(0);
    ui->stackedWidget->setCurrentIndex(1);
}

//======================================================================================================================
//
void on_again_btn_valueChanged(int value)
{
    m_browseform->ae_again = value;
    ui->again_btn->setValue(value);
    ui->again_label->setText(QString::number(value));
}


//======================================================================================================================
//
void on_dgain_btn_valueChanged(int value)
{
    m_browseform->ae_dgain = value;
    ui->dgain_btn->setValue(value);
    ui->dgain_label->setText(QString::number(value));
}

//======================================================================================================================
//
void on_exposure_btn_valueChanged(int value)
{
    m_browseform->ae_exposure = value;
    ui->exposure_btn->setValue(value);
    ui->exposure_label->setText(QString::number(value));
}

//======================================================================================================================
//
void on_ispgain_btn_valueChanged(int value)
{
    m_browseform->ae_ispdgain = value;
    ui->ispgain_btn->setValue(value);
    ui->ispgain_label->setText(QString::number(value));
}

//======================================================================================================================
//
void on_pre1_clicked()
{
    ui->setting->setCurrentIndex(0);
}

//======================================================================================================================
//
void on_next1_clicked()
{
    ui->setting->setCurrentIndex(2);
}



//======================================================================================================================
void on_save1_clicked()
{
    QSettings settings(PARAM_FILE, QSettings::IniFormat);
    settings.setValue("isp/ae_again", m_browseform->ae_again);
    settings.setValue("isp/ae_dgain", m_browseform->ae_dgain);
    settings.setValue("isp/ae_exposure", m_browseform->ae_exposure);
    settings.setValue("isp/ae_ispdgain", m_browseform->ae_ispdgain);
}

//======================================================================================================================
//
void on_brightness_btn_valueChanged(int value)
{
    m_browseform->csc_brightness = value;
    ui->brightness_btn->setValue(value);
    ui->brightness_label->setText(QString::number(value));
}


//======================================================================================================================
void on_constrast_btn_valueChanged(int value)
{
    m_browseform->csc_constrast = value;
    ui->constrast_btn->setValue(value);
    ui->constrast_label->setText(QString::number(value));
}


//======================================================================================================================
void on_hue_btn_valueChanged(int value)
{
    m_browseform->csc_hue = value;
    ui->hue_btn->setValue(value);
    ui->hue_label->setText(QString::number(value));
}


//======================================================================================================================
void on_saturastion_btn_valueChanged(int value)
{
    m_browseform->csc_saturation = value;
    ui->saturastion_btn->setValue(value);
    ui->saturastion_label->setText(QString::number(value));
}


//======================================================================================================================
void on_pre1_2_clicked()
{
    ui->setting->setCurrentIndex(1);
}


//======================================================================================================================
void on_next1_2_clicked()
{
    ui->setting->setCurrentIndex(3);
}


//======================================================================================================================
void on_save1_2_clicked()
{
    QSettings settings(PARAM_FILE, QSettings::IniFormat);
    settings.setValue("isp/csc_brightness", m_browseform->csc_brightness);
    settings.setValue("isp/csc_constrast", m_browseform->csc_constrast);
    settings.setValue("isp/csc_hue", m_browseform->csc_hue);
    settings.setValue("isp/csc_saturation", m_browseform->csc_saturation);
}


//======================================================================================================================
void on_rgain_btn_valueChanged(int value)
{
    m_browseform->awb_rgain = value;
    ui->rgain_btn->setValue(value);
    ui->rgain_label->setText(QString::number(value));
}


//======================================================================================================================
void on_grgain_btn_valueChanged(int value)
{
    m_browseform->awb_grgain = value;
    ui->grgain_btn->setValue(value);
    ui->grgain_label->setText(QString::number(value));
}


//======================================================================================================================
void on_gbgain_btn_valueChanged(int value)
{
    m_browseform->awb_gbgain = value;
    ui->gbgain_btn->setValue(value);
    ui->gbgain_label->setText(QString::number(value));
}


//======================================================================================================================
void on_bgain_btn_valueChanged(int value)
{
    m_browseform->awb_bgain = value;
    ui->bgain_btn->setValue(value);
    ui->bgain_label->setText(QString::number(value));
}


//======================================================================================================================
void on_pre1_3_clicked()
{
    ui->setting->setCurrentIndex(2);
}


//======================================================================================================================
void on_next1_3_clicked()
{
    ui->setting->setCurrentIndex(4);
}


//======================================================================================================================
void on_save1_3_clicked()
{
    QSettings settings(PARAM_FILE, QSettings::IniFormat);
    settings.setValue("isp/awb_awbmode", m_browseform->awb_awbmode);
    settings.setValue("isp/awb_temperature", m_browseform->awb_temperature);
    settings.setValue("isp/awb_rgain", m_browseform->awb_rgain);
    settings.setValue("isp/awb_grgain", m_browseform->awb_grgain);
    settings.setValue("isp/awb_gbgain", m_browseform->awb_gbgain);
    settings.setValue("isp/awb_bgain", m_browseform->awb_bgain);
}


//======================================================================================================================
void on_texturefreq_btn_valueChanged(int value)
{
    m_browseform->sharp_texturefreq = value;
    ui->texturefreq_btn->setValue(value);
    ui->texturefreq_label->setText(QString::number(value));
}


//======================================================================================================================
void on_edgefreq_btn_valueChanged(int value)
{
    m_browseform->sharp_edgefreq = value;
    ui->edgefreq_btn->setValue(value);
    ui->edgefreq_label->setText(QString::number(value));
}


//======================================================================================================================
void on_overshoot_btn_valueChanged(int value)
{
    m_browseform->sharp_overshoot = value;
    ui->overshoot_btn->setValue(value);
    ui->overshoot_label->setText(QString::number(value));
}


//======================================================================================================================
void on_undershoot_btn_valueChanged(int value)
{
    m_browseform->sharp_undershoot = value;
    ui->undershoot_btn->setValue(value);
    ui->undershoot_label->setText(QString::number(value));
}


//======================================================================================================================
void on_pre1_4_clicked()
{
    ui->setting->setCurrentIndex(3);
}


//======================================================================================================================
void on_next1_4_clicked()
{
    ui->setting->setCurrentIndex(5);
}


//======================================================================================================================
void on_save1_4_clicked()
{
    QSettings settings(PARAM_FILE, QSettings::IniFormat);
    settings.setValue("isp/sharp_mode", m_browseform->sharp_mode);
    settings.setValue("isp/sharp_texturefreq", m_browseform->sharp_texturefreq);
    settings.setValue("isp/sharp_edgefreq", m_browseform->sharp_edgefreq);
    settings.setValue("isp/sharp_overshoot", m_browseform->sharp_overshoot);
    settings.setValue("isp/sharp_undershoot", m_browseform->sharp_undershoot);
}


//======================================================================================================================
void on_pre1_6_clicked()
{
    ISP_AWB_Calibration_Gain_S stAWBCalibGain;
    mppAwbCalibration(0,0,&stAWBCalibGain);
    r_value.setNum(stAWBCalibGain.u16AvgRgain);
    g_value.setNum(stAWBCalibGain.u16AvgBgain);
    ui->awb_6->setText(r_value);
    ui->awb_7->setText(g_value);
}


//======================================================================================================================
void on_pre1_7_clicked()
{
    ISP_AWB_Calibration_Gain_S stAWBCalibGain;
    mppAwbCalibration(0,0,&stAWBCalibGain);
    r_value.setNum(stAWBCalibGain.u16AvgRgain);
    g_value.setNum(stAWBCalibGain.u16AvgBgain);
    ui->awb_10->setText(r_value);
    ui->awb_11->setText(g_value);
}


//======================================================================================================================
void on_pre1_5_clicked()
{
    ui->setting->setCurrentIndex(4);
}


//======================================================================================================================
void on_next1_6_clicked()
{
    ui->setting->setCurrentIndex(6);
}


//======================================================================================================================
void on_save1_6_clicked()
{
    FILE* fd;
    char args[60];
    sprintf(args,"%4s %4s",r_value.toLocal8Bit().data(),g_value.toLocal8Bit().data());
    system(args);
    fd = fopen("/etc/awb","w+");
    fwrite(args,1,45,fd);
    fclose(fd);
}


#endif
